This article mainly and we introduce how PHP obtains the current host, domain name, url, path, port and other parameters, with a certain reference value, interested can understand, hope to help everyone.
Lab Environment:
Test the domain name Daxiangtravel.com,apache root directory/mnt/, test the directory/mnt/qa/test, the test file is named index.php.
Get the code:
Get current directory:
GETCWD ();///mnt/qa/testdirname (__file__);///mnt/qa/test
Get domain name or host address
$_server[' Http_host ']; Daxiangtravel.com
Get web Address
$_server[' php_self '];///qa/test/index.php
Get URL parameters
$_server["Query_string"];//v=433 get user agent $_server[' http_referer '];//http://daxiangtravel.com/qa/test/index.php?v=433
Get the full URL
' http://' $_server[' http_host '].$_server[' Request_uri '];//http://daxiangtravel.com/qa/test/index.php?v=433 ' http://'. $_server[' http_host '].$_server[' php_self ']. $_server[' query_string '];//http://daxiangtravel.com/qa/test/index.php?v=433
Fetch path only
$url = ' http://' $_server[' server_name '].$_server["Request_uri"];echo dirname ($url);//Http://daxiangtravel.com/qa/test
Full URL with port number
' http://'. ' $_server[' server_name '. $_server["Server_port"].$_server["Request_uri"];///http/ daxiangtravel.com:80/qa/test/index.php?v=433