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.

CHAPTER 3 • <strong>PHP</strong> BASICSwww.it-ebooks.infoThis returns a list of variables similar to the following. Take a moment to peruse the listing producedby this code as executed on a Windows server. You’ll see some of these variables again in the examplesthat follow:HTTP_HOST => localhostHTTP_USER_AGENT => 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.3HTTP_ACCEPT => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8HTTP_ACCEPT_LANGUAGE => en-us,en;q=0.5HTTP_ACCEPT_ENCODING => gzip,deflateHTTP_ACCEPT_CHARSET => ISO-8859-1,utf-8;q=0.7,*;q=0.7HTTP_KEEP_ALIVE => 300HTTP_CONNECTION => keep-aliveHTTP_REFERER => http://localhost/chapter03/HTTP_COOKIE => <strong>PHP</strong>SESSID=205jm6q0lcj867h8p05umfthm7PATH => C:\php5212\;C:\Ruby\bin;C:\Program Files\Windows ResourceKits\Tools\;C:\WINDOWS\system32;C:\WINDOWS;C:\mysql\bin;C:\ProgramFiles\Java\jdk1.6.0_14\bin;C:\php\PEAR;C:\Program Files\GTK2-Runtime\bin;C:\ProgramFiles\jEdit;C:\libxslt\bin;C:\libxml2\bin;C:\apache-ant-1.7.1\binSystemRoot => C:\WINDOWSCOMSPEC => C:\WINDOWS\system32\cmd.exePATHEXT => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBWWINDIR => C:\WINDOWSSERVER_SIGNATURE =>SERVER_SOFTWARE => Apache/2.2.11 (Win32) <strong>PHP</strong>/5.2.12SERVER_NAME => localhostSERVER_ADDR => 127.0.0.1SERVER_PORT => 80REMOTE_ADDR => 127.0.0.1DOCUMENT_ROOT => C:/apache/htdocs/beginningphpandmysql_4eSERVER_ADMIN => admin@localhostSCRIPT_FILENAME => C:/apache/htdocs/beginningphpandmysql_4e/chapter03/server-superglobal.phpREMOTE_PORT => 4298GATEWAY_INTERFACE => CGI/1.1SERVER_PROTOCOL => HTTP/1.1REQUEST_METHOD => GETQUERY_STRING =>REQUEST_URI => /chapter03/server-superglobal.phpSCRIPT_NAME => /chapter03/server-superglobal.php<strong>PHP</strong>_SELF => /chapter03/server-superglobal.phpREQUEST_TIME => 1262728260As you can see, quite a bit of information is available—some useful, some not so useful. You candisplay just one of these variables simply by treating it as a regular variable. For example, use this todisplay the user’s IP address:printf("Your IP address is: %s", $_SERVER['REMOTE_ADDR']);This returns a numerical IP address, such as 192.0.34.166.You can also gain information regarding the user’s browser and operating system. Consider thefollowing one-liner:62

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

Saved successfully!

Ooh no, something went wrong!