开发者

How to determine which URL accessed the script

How do I tell if my script was accessed as http://localhost/myfile.php or, for example, http://222.22.22.22/myfile.php开发者_高级运维? I need to get the 222.22.22.22 part as a string


For info about "http://example.com:8080/myfile.php" you've got the following options:

echo $_SERVER['HTTP_HOST'];
"example.com:8080"

echo $_SERVER['SERVER_NAME'];
"example.com"

echo $_SERVER['SERVER_PORT'];
8080

If the server run on port 80 the $_SERVER['HTTP_HOST'] won't contain the port number.


$_SERVER['HTTP_HOST'] will hold the part of the request URI you're looking for


$_SERVER["SCRIPT_URI"]

More info on all of the available $_SERVER variables are in the PHP reference at http://www.php.net/manual/en/reserved.variables.server.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜