Reputation: 66965
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
Upvotes: 1
Views: 116
Reputation: 29907
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.
Upvotes: 2
Reputation: 813
$_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
Upvotes: 0
Reputation: 175585
$_SERVER['HTTP_HOST']
will hold the part of the request URI you're looking for
Upvotes: 0