How to check address a page is accessed from?
I was wondering if it is possible to grab the URL from 开发者_开发百科which a page is accessed? For example say if I have a file index.php. It can be accessed from virtually anywhere, depending on where I placed it. For example:
- http://folder1/index.php
- http://nicefolder1/index.php
Is there anyway I can find out where the page was accessed from? I'd like to perhaps parse that URL and if it was from nicefolder1, I'd like to do something like echo "That was a good location to be executed from"
:D! Just something I was curious about ...
$_SERVER['PHP_SELF']
Should have the url you want.
More Info
I am not sure if I understand your question, but here's my take on this:
$_SERVER['HTTP_HOST']
holds the host name, and $_SERVER['REQUEST_URI']
the absolute path to the requested resource. These two, combined with a scheme prefix, gives you the complete URL:
$url = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
Take a look at the $_SERVER reference on php.net, $_SERVER['PHP_SELF'] should do the trick.
精彩评论