<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>$GLOBALS全局變量與$_SERVER伺服器的資訊</title>
</head>
<body>
<?php
//$GLOBALS為全局變量
$x = 75;
$y = 25;
$GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
echo $z;
echo "<br>";
//$_SERVER為伺服器的資訊,例位置為http://localhost/GLOBALS.php (伺服器不一定全部都能使用)
echo "PHP_SELF=>".$_SERVER['PHP_SELF'];//檔案位置不包含http://localhost/,只顯示GLOBALS.php
echo "<br>";
echo "GATEWAY_INTERFACE=>".$_SERVER['GATEWAY_INTERFACE'];//CGI/1.1
echo "<br>";
echo "SERVER_ADDR=>".$_SERVER['SERVER_ADDR'];//::1
echo "<br>";
echo "SERVER_NAME=>".$_SERVER['SERVER_NAME'];//只顯示localhost
echo "<br>";
echo "SERVER_SOFTWARE=>".$_SERVER['SERVER_SOFTWARE'];//Apache/2.4.7 (Win32) PHP/5.4.24
echo "<br>";
echo "SERVER_PROTOCOL=>".$_SERVER['SERVER_PROTOCOL'];//HTTP/1.1
echo "<br>";
echo "REQUEST_METHOD=>".$_SERVER['REQUEST_METHOD'];//對應下面是使用post就顯示POST
echo "<br>";
echo "REQUEST_TIME=>".$_SERVER['REQUEST_TIME'];//1571071590
echo "<br>";
echo "QUERY_STRING=>".$_SERVER['QUERY_STRING'];//對應下面是happy欄位輸入ddd而顯示happy=ddd
echo "<br>";
echo "HTTP_ACCEPT=>".$_SERVER['HTTP_ACCEPT'];//text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
echo "<br>";
echo "HTTP_ACCEPT_CHARSET=>".$_SERVER['HTTP_ACCEPT_CHARSET'];
echo "<br>";
echo "HTTP_HOST=>".$_SERVER['HTTP_HOST'];//只顯示localhost
echo "<br>";
echo "HTTP_REFERER=>".$_SERVER['HTTP_REFERER'];//http://localhost/GLOBALS.php
echo "<br>";
echo "HTTPS=>".$_SERVER['HTTPS'];
echo "<br>";
echo "REMOTE_ADDR=>".$_SERVER['REMOTE_ADDR'];//::1
echo "<br>";
echo "REMOTE_HOST=>".$_SERVER['REMOTE_HOST'];
echo "<br>";
echo "REMOTE_PORT=>".$_SERVER['REMOTE_PORT'];
echo "<br>";
echo "SCRIPT_FILENAME=>".$_SERVER['SCRIPT_FILENAME'];//本機位置G:/EasyPHP-DevServer-14.1VC9 20161012/php/GLOBALS.php
echo "<br>";
echo "SERVER_ADMIN=>".$_SERVER['SERVER_ADMIN'];//admin@127.0.0.1
echo "<br>";
echo "SERVER_PORT=>".$_SERVER['SERVER_PORT'];//80
echo "<br>";
echo "SERVER_SIGNATURE=>".$_SERVER['SERVER_SIGNATURE'];
echo "<br>";
echo "PATH_TRANSLATED=>".$_SERVER['PATH_TRANSLATED'];
echo "<br>";
echo "SCRIPT_NAME=>".$_SERVER['SCRIPT_NAME'];//GLOBALS.php
echo "<br>";
echo "SCRIPT_URI=>".$_SERVER['SCRIPT_URI'];
echo "<br>";
echo "HTTP_USER_AGENT=>".$_SERVER['HTTP_USER_AGENT'];//Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
echo "<br>";
echo "SCRIPT_NAME=>".$_SERVER['SCRIPT_NAME'];//GLOBALS.php
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name:<input type="text" name="happy">
<input type="submit">
</form>
<?php
//$_REQUEST 用於收集HTML表單提交的資料。$_GET/$_POST會直接抓這兩個有相同名字的值。
$n1 = $_REQUEST['happy'];
$n2=$_POST['happy'];
echo "\$_REQUEST=>".$n1.",\$_POST=>".$n2;
echo "<br>";
?>
</body>
</html>
留言列表