This article describes how PHP can obtain parameters such as the current host, domain name, URL, path, and port, if you are interested, please refer to this article. This article describes how PHP can obtain parameters such as the current host, domain name, URL, path, and port.
Lab environment:
The test domain name is daxiangtravel.com, the apache root directory/mnt/, the test directory/mnt/qa/test, and the test file name is index. php.
Get Code:
Get the current directory:
getcwd();// /mnt/qa/testdirname(__FILE__);// /mnt/qa/test
Get domain name or host address
$_SERVER['HTTP_HOST']; //daxiangtravel.com
Get webpage address
$_SERVER['PHP_SELF'];// /qa/test/index.php
Obtain URL parameters
$ _ SERVER ["QUERY_STRING"]; // v = 433 get user proxy $ _ SERVER ['http _ referer']; // http://daxiangtravel.com/qa/test/index.php? V = 433
Obtain the complete 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
Retrieve path only
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];echo dirname($url);// http://daxiangtravel.com/qa/test
Complete url containing the port number
'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];// http://daxiangtravel.com:80/qa/test/index.php?v=433
The preceding section describes how to use PHP to obtain details about the current host, domain name, URL, path, port, and other parameters. For more information, see other related articles in the first PHP community!