irwan

PHP Server Array Variables Tutorial with Sample Test Script

Apr 8th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.87 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Most Commonly Used Server Array Variables in PHP</title>
  4. <meta name="ROBOTS" content="NOINDEX">
  5. <style type="text/css">
  6. body {
  7. font-family:'Verdana';
  8. font-size:12px
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <h3>Below are the most commonly used server array variables in PHP</h3><br />
  14. Overview: This is just an outputted HTML of the PHP server side script that utilizes the server variables below.<br />
  15. If you like to know the details, this is what happens: <br />
  16. Step 1. You click the link on <br />
  17. Step 2. The server receives that request and executes the PHP code that includes the server variables.<br />
  18. If you need to see the exact PHP script, visit this post:<br />
  19. Step 3. After executing the PHP code, it will then output the result as PLAIN HTML CODE TO THE BROWSER.<br />
  20. Step 4. The browser receives the request in HTML form and renders it so that you can SEE and READ the content.<br />
  21. Enough of the background, lets study how PHP respond the server variables below (in red font are the server variable OUTPUTS):<br />
  22. <p><font color="blue">Server variable 1:</font><font color="green"> $_SERVER['REQUEST_URI']</font></p>
  23. <?php echo "Server REQUEST URI value of this URL/Server is:  ".'<font color="red">'.$_SERVER['REQUEST_URI'].'</font><br />'; ?>
  24. Note: This the requested file name/URL to the server. You can use this variable to identify the requested URL.
  25. <p><font color="blue">Server variable 2:</font><font color="green"> $_SERVER['HTTP_HOST']</font></p>
  26. <?php echo "Server HTTP HOST value of this URL/Server is:  ".'<font color="red">'.$_SERVER['HTTP_HOST'].'</font><br />'; ?>
  27. Note: This the server hostname. This is used to get the hostname.
  28. <p><font color="blue">Server variable 3:</font><font color="green"> $_SERVER['DOCUMENT_ROOT']</font><p>
  29. <?php echo "Server DOCUMENT ROOT value of this URL/Server is:  ".'<font color="red">'.$_SERVER['DOCUMENT_ROOT'].'</font><br />'; ?>
  30. Note: This is the file path of the root directory.
  31. <p><font color="blue">Server variable 4:</font><font color="green"> $_SERVER['SERVER_NAME']</font><p>
  32. <?php echo "Server SERVER NAME value of this URL/Server is:  ".'<font color="red">'.$_SERVER['SERVER_NAME'].'</font><br />'; ?>
  33. Note: This is the server name, analogous to the domain name of the requested URL.
  34. <p><font color="blue">Server variable 5:</font><font color="green"> $_SERVER['HTTP_REFERER']</font><p>
  35. <?php echo "Server HTTP REFERER value of this URL/Server is:  ".'<font color="red">'.$_SERVER['HTTP_REFERER'].'</font><br />'; ?>
  36. Note: This gives the referer URL to this page
  37. <p><font color="blue">Server variable 6:</font><font color="green"> $_SERVER['HTTP_USER_AGENT']</font><p>
  38. <?php echo "Server HTTP USER AGENT value of this URL/Server is:  ".'<font color="red">'.$_SERVER['HTTP_USER_AGENT'].'</font><br />'; ?>
  39. Note: This gives the exact name of the browser you are using.
  40. <p><font color="blue">Server variable 7:</font><font color="green"> $_SERVER['SERVER_PROTOCOL']</font><p>
  41. <?php echo "Server HTTP SERVER PROTOCOL value of this URL/Server is:  ".'<font color="red">'.$_SERVER['SERVER_PROTOCOL'].'</font><br />'; ?>
  42. Note: This is the HTTP protocol version.
  43. <p><font color="blue">Server variable 8:</font><font color="green"> $_SERVER['PHP_SELF']</font><p>
  44. <?php echo "Server HTTP PHP SELF value of this URL/Server is:  ".'<font color="red">'.$_SERVER['PHP_SELF'].'</font><br />'; ?>
  45. Note: This is used in submitting form data to itself, eliminating the need of another files.
  46. <p><font color="blue">Server variable 9:</font><font color="green"> $_SERVER['REMOTE_ADDR']</font><p>
  47. <?php echo "Server Remote ADDR value of this URL/Server is:  ".'<font color="red">'.$_SERVER['REMOTE_ADDR'].'</font><br />'; ?>
  48. Note: This is your IP address.
  49. <p><font color="blue">Server variable 10:</font><font color="green"> $_SERVER['SCRIPT_FILENAME']</font><p>
  50. <?php echo "Server Script Filename of this URL/Server is:  ".'<font color="red">'.$_SERVER['SCRIPT_FILENAME'].'</font><br />'; ?>
  51. Note: This is the actual file location of this accessed URL with respect to the server.
  52. <p><font color="blue">Server variable 11:</font><font color="green"> $_SERVER['SERVER_ADDR']</font><p>
  53. <?php echo "Server ADDR value is:  ".'<font color="red">'.$_SERVER['SERVER_ADDR'].'</font><br />'; ?>
  54. Note: This is the Server IP location.
  55. <p><font color="blue">Server variable 12:</font><font color="green"> $_SERVER['GATEWAY_INTERFACE']</font><p>
  56. <?php echo "Server Common gateway interface value of this URL/Server is:  ".'<font color="red">'.$_SERVER['GATEWAY_INTERFACE'].'</font><br />'; ?>
  57. Note: This is the common gateway interface.
  58. <p><font color="blue">Server variable 13:</font><font color="green"> $_SERVER['REQUEST_METHOD']</font><p>
  59. <?php echo "Server Request method value of this URL/Server is:  ".'<font color="red">'.$_SERVER['REQUEST_METHOD'].'</font><br />'; ?>
  60. Note: This is the server request method.
  61. <p><font color="blue">Server variable 14:</font><font color="green"> $_SERVER['SERVER_SOFTWARE']</font><p>
  62. <?php echo "Server software value of this URL/Server is:  ".'<font color="red">'.$_SERVER['SERVER_SOFTWARE'].'</font><br />'; ?>
  63. Note: This is the software used by the server.
  64. <p><font color="blue">Server variable 15:</font><font color="green"> $_SERVER['REMOTE_PORT']</font><p>
  65. <?php echo "Server Remote Port value is:  ".'<font color="red">'.$_SERVER['REMOTE_PORT'].'</font><br />'; ?>
  66. Note: This is your port number used in accessing this content.
  67. <p><font color="blue">Server variable 16:</font><font color="green"> $_SERVER['SERVER_PORT']</font><p>
  68. <?php echo "Server Port Number is:  ".'<font color="red">'.$_SERVER['SERVER_PORT'].'</font><br />'; ?>
  69. Note: This is the server port number used.
  70. <p><font color="blue">Server variable 17:</font><font color="green"> $_SERVER['REMOTE_HOST']</font><p>
  71. <?php echo "The remote host is:  ".'<font color="red">'.$_SERVER['REMOTE_HOST'].'</font><br />'; ?>
  72. Note: This is the remote host.
  73. </body>
  74. </html>
Advertisement
Add Comment
Please, Sign In to add comment