$_SERVER
About $_SERVER

$_SERVER is a super global variable that contain information about web application like determining browser type etc.

we are discussing some usefull $_SERVER variable.

$_SERVER[\'SERVER_NAME\']:-

To get server same under which script is executing
Example:-
<?php
echo $_SERVER[\'SERVER_NAME\'].\"<br>\";
?>

Output:-
To get server name like www.ittestonline.net

$_SERVER[\'HTTP_REFERER\']:-

The url of the page that referred  to current page.
Example:-

page test1.php
<html>
<head>
<title>server variable</title>
</head>
<body>
<a href=\"test2.php\">click here</a>
</body>
</html>

page test2.php
<?php
echo $_SERVER[\'HTTP_REFERER\'].\"<br>\";
?>

Output:-
This scrpt will returns the url of previous page(test1.php)

$_SERVER[\'REMOTE_ADDR\']:-

To get to know the IP address the system.
Example:-
<?php
echo $_SERVER[\'REMOTE_ADDR\'];
?>

Output:-
IP Address of the system.

$_SERVER[\'HTTP_USER_AGENT\']:-

To get to know broswer type
Example:-
<?php
if(strpos($_SERVER[\'HTTP_USER_AGENT\'],\"Firefox\"))
echo \"You are using Mozilla firefox\";
elseif(strpos($_SERVER[\'HTTP_USER_AGENT\'],\"MSIE\"))
echo \"You are using Internet Explorer\";
elseif(strpos($_SERVER[\'HTTP_USER_AGENT\'],\"Chrome\"))
echo \"You are using Google chrome\";
elseif(strpos($_SERVER[\'HTTP_USER_AGENT\'],\"Safari\"))
echo \"You are using Safari\";
?>

Output:-
Return browser type


Previous
Next