11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 3 • <strong>PHP</strong> BASICSprintf("Your browser is: %s", $_SERVER['HTTP_USER_AGENT']);This returns information similar to the following:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6(.NET CLR 3.5.30729) Fire<strong>PHP</strong>/0.3This example illustrates only one of <strong>PHP</strong>’s nine predefined variable arrays. The rest of this section isdevoted to introducing the purpose and contents of each.■ Note To use the predefined variable arrays, the configuration parameter track_vars must be enabled in thephp.ini file. As of <strong>PHP</strong> 4.03, track_vars is always enabled.Learning More About the Server and ClientThe $_SERVER superglobal contains information created by the web server—details regarding the serverand client configuration and the current request environment. Although the value and number ofvariables found in $_SERVER varies by server, you can typically expect to find those defined in the CGI 1.1specification (www.w3.org/CGI) . You’ll likely find all of these variables to be quite useful in yourapplications, some of which include the following:$_SERVER['HTTP_REFERER']: The URL of the page that referred the user to thecurrent location.$_SERVER['REMOTE_ADDR']: The client’s IP address.$_SERVER['REQUEST_URI']: The path component of the URL. For example, if theURL is http://www.example.com/blog/apache/index.html, the URI is/blog/apache/index.html.$_SERVER['HTTP_USER_AGENT']: The client’s user agent, which typically offersinformation about both the operating system and the browser.Retrieving Variables Passed Using GETThe $_GET superglobal contains information pertinent to any parameters passed using the GET method.If the URL http://www.example.com/index.html?cat=apache&id=157 is requested, you could access thefollowing variables by using the $_GET superglobal:$_GET['cat'] = "apache"$_GET['id'] = "157"The $_GET superglobal by default is the only way that you can access variables passed via the GETmethod. You cannot reference GET variables like this: $cat, $id. See Chapter 13 for more about formsprocessing with <strong>PHP</strong>, and Chapter 13 for more about safely accessing external data.63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!