Mảng $_SERVER là 1 mảng
được xác định trước, được thiết lập bới máy chủ web (wampserver)
Thực hiện print toàn bộ thông tin về mảng $_SERVER
<?php
echo
"<pre>";
print_r($_SERVER);
kết quả:
-Array
(
[HTTP_HOST] => localhost
[HTTP_CONNECTION]
=> keep-alive
[HTTP_UPGRADE_INSECURE_REQUESTS]
=> 1
[HTTP_USER_AGENT]
=> Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/84.0.4147.105 Safari/537.36
[HTTP_ACCEPT]
=> text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
[HTTP_SEC_FETCH_SITE]
=> same-origin
[HTTP_SEC_FETCH_MODE]
=> navigate
[HTTP_SEC_FETCH_USER]
=> ?1
[HTTP_SEC_FETCH_DEST]
=> document
[HTTP_REFERER] =>
http://localhost/demo/mangserver/
[HTTP_ACCEPT_ENCODING]
=> gzip, deflate, br
[HTTP_ACCEPT_LANGUAGE]
=> en-US,en-CA;q=0.9,en;q=0.8,zh-CN;q=0.7,zh;q=0.6
[PATH]
=> E:\Program Files (x86)\Common Files\Intel\Shared
Files\cpp\bin\Intel64;E:\Windows\system32;E:\Windows;E:\Windows\System32\Wbem;E:\Windows\System32\WindowsPowerShell\v1.0\;E:\Program
Files (x86)\NVIDIA Corporation\PhysX\Common;E:\wamp64\bin\php\php7.4.0;
[SystemRoot]
=> E:\Windows
[COMSPEC]
=> E:\Windows\system32\cmd.exe
[PATHEXT]
=> .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
[WINDIR]
=> E:\Windows
[SERVER_SIGNATURE]
=>
Apache/2.4.41 (Win64)
PHP/7.3.12 Server at localhost Port 80
[SERVER_SOFTWARE]
=> Apache/2.4.41 (Win64) PHP/7.3.12
[SERVER_NAME]
=> localhost
[SERVER_ADDR]
=> ::1
[SERVER_PORT]
=> 80
[REMOTE_ADDR]
=> ::1
[DOCUMENT_ROOT]
=> E:/wamp64/www
[REQUEST_SCHEME]
=> http
[CONTEXT_PREFIX]
=>
[CONTEXT_DOCUMENT_ROOT] =>
E:/wamp64/www
[SERVER_ADMIN]
=> wampserver@wampserver.invalid
[SCRIPT_FILENAME]
=> E:/wamp64/www/demo/mangserver/mangserver.php
[REMOTE_PORT]
=> 50746
[GATEWAY_INTERFACE]
=> CGI/1.1
[SERVER_PROTOCOL]
=> HTTP/1.1
[REQUEST_METHOD]
=> GET
[QUERY_STRING]
=>
[REQUEST_URI]
=> /demo/mangserver/mangserver.php
[SCRIPT_NAME]
=> /demo/mangserver/mangserver.php
[PHP_SELF]
=> /demo/mangserver/mangserver.php
[REQUEST_TIME_FLOAT]
=> 1596252364.334
[REQUEST_TIME]
=> 1596252364
)
In ra các thông tin cần
thiết:
<?php
echo "tra ve ten
file php dang chay <br>";
echo
$_SERVER['SCRIPT_FILENAME']; echo "<br>";
echo "tra ve ten
may chu <br>";
echo
$_SERVER['SERVER_NAME'];echo "<br>";
echo "tra ve duong
dan thu muc dang chay file php <br>";
echo
$_SERVER['HTTP_REFERER'];echo "<br>";
echo "tra ve
ten&phien ban webserver <br>";
echo
$_SERVER['SERVER_SOFTWARE'];echo "<br>";
echo "tra ve phuong
thuc yeu cau";
echo
$_SERVER['REQUEST_METHOD'];echo "<br>";
echo "The query
string is: ".$_SERVER['QUERY_STRING'];echo "<br>";
kết quả:
tra ve ten file php dang
chay
E:/wamp64/www/demo/mangserver/mangserver.php
tra ve ten may chu
localhost
tra ve duong dan thu muc
dang chay file php
http://localhost/demo/mangserver/
tra ve ten&phien ban
webserver
Apache/2.4.41 (Win64) PHP/7.3.12
tra ve phuong thuc yeu cau
GET
The query string is: