Home Tutorial Php Phpbasics Tutorial PHP Variable Server

 
 

Share on Google+Share on Google+
PHP Variable Server
Posted on: February 5, 2010 at 12:00 AM
Advertisement
This tutorial will explain the $_SERVER variable of PHP. $_SERVER is an array which is used to display the server and environment related information. It contains information such as headers, paths, and script locations. The entries in this array are created by the server. Various examples will help you to understand the similarity as well as the differences of methods.

$_SERVER

$_SERVER is an array which is used to display the server and environment related information. It contains information such as headers, paths, and script locations. The entries in this array are created by the server.

In the following example, you can check few indices of $_SERVER:

Example:

<?php

echo "<b>Gateway Interface : </b>".$_SERVER['GATEWAY_INTERFACE']."<br/>";

echo "<b>Server address : </b>".$_SERVER['SERVER_ADDR']."<br/>";

echo "<b>Server name : </b>".$_SERVER['SERVER_NAME']."<br/>";

echo "<b>Server software : </b>".$_SERVER['SERVER_SOFTWARE']."<br/>";

echo "<b>Server protocol : </b>".$_SERVER['SERVER_PROTOCOL']."<br/>";

echo "<b>Server request method : </b>".$_SERVER['REQUEST_METHOD']."<br/>";

echo "<b>Server request time : </b>".$_SERVER['REQUEST_TIME']."<br/>";

echo "<b>Document root : </b>".$_SERVER['DOCUMENT_ROOT']."<br/>";

echo "<b>Http accept : </b>".$_SERVER['HTTP_ACCEPT']."<br/>";

echo "<b>Http accept charset root : </b>".$_SERVER['HTTP_ACCEPT_CHARSET']."<br/>";

echo "<b>Http accept encoding : </b>".$_SERVER['HTTP_ACCEPT_ENCODING']."<br/>";

echo "<b>Http accept language : </b>".$_SERVER['HTTP_ACCEPT_LANGUAGE']."<br/>";

echo "<b>Http connection : </b>".$_SERVER['HTTP_CONNECTION']."<br/>";

echo "<b>Http referer : </b>".$_SERVER['HTTP_REFERER']."<br/>";

echo "<b>Http user agent : </b>".$_SERVER['HTTP_USER_AGENT']."<br/>";

echo "<b>Remote address : </b>".$_SERVER['REMOTE_ADDR']."<br/>";

echo "<b>Remote port : </b>".$_SERVER['REMOTE_PORT']."<br/>";

echo "<b>Script Filename : </b>".$_SERVER['SCRIPT_FILENAME']."<br/>";

echo "<b>Server admin : </b>".$_SERVER['SERVER_ADMIN']."<br/>";

echo "<b>Server port : </b>".$_SERVER['SERVER_PORT']."<br/>";

echo "<b>Script name : </b>".$_SERVER['SCRIPT_NAME']."<br/>";

echo "<b>Request URI : </b>".$_SERVER['REQUEST_URI']."<br/>";

?>

 

Output:

Gateway Interface : CGI/1.1
Server address : 127.0.0.1
Server name : localhost
Server software : Apache/2.2.8 (Win32) PHP/5.2.6
Server protocol : HTTP/1.1
Server request method : GET
Server request time : 1265279956
Document root : C:/wamp/www/
Http accept : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Http accept charset root : ISO-8859-1,utf-8;q=0.7,*;q=0.7
Http accept encoding : gzip,deflate
Http accept language : en-us,en;q=0.5
Http connection : keep-alive
Http referer : http://localhost/basu/
Http user agent : Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
Remote address : 127.0.0.1
Remote port : 1555
Script Filename : C:/wamp/www/basu/server.php
Server admin : admin@localhost
Server port : 80
Script name : /basu/server.php
Request URI : /basu/server.php

Advertisement

Related Tags for PHP Variable Server:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 5, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com