PHP $_SERVER
Example-
<!DOCTYPE html>
<html>
<body>
<?php
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo $_SERVER['HTTP_REFERER'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
?>
</body>
</html>
The output of the above code are:-
/php/demo_global_server.phpwww.w3schools.com
www.w3schools.com
http://www.w3schools.com/php/showphp.asp?filename=demo_global_server
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
/php/demo_global_server.php
$_REQUEST
It is used to collect data after submitting an HTML form.
Example:-
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field $name = $_REQUEST['fname'];
if (empty($name)) {
echo "Name
is empty";
} else {
echo $name;
}
}
?>
</body>
</html>
Copy the above code run on your localhost to get the result to hope you like this post In My next post I will explain the practice of the GET and POST method...How the GET and POST Method works in PHP...and what is the difference between the post and gets method?? If you want to follow me on google+ then click on the google+ button in my post thankyou.....
0 Comments