How can I find out where a user has come from when they use GET?

How can I find the URL or file name of the page last visited by a user that uses a GET request method?  For example, if someone makes a PHP script using this code:


How can detect if they went straight to the main menu and by-passed the login page?
There's no 'HTTP_REFERER' evironment variable like there is when a POST is used.

ps. Can this be done w/o using cookies?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

chippleConnect With a Mentor Commented:
If there's no HTTP_REFERER, then the user either went straight to the main menu, or the user doesn't have a browser that supports HTTP_REFERER [correctly].
If that's not enough, you'll have to use cookies, session, etc.

You can't go directly to a page using POST with a regular Web browser. You can however do POST requests using script, like this example:

$fp = fsockopen("",80);
fwrite($fp,'POST /mainMenu.php HTTP/1.0
$buf = "";
whlie (!feof($fp)) $buf .= fred($fp,0x1000);

Good luck.
HTTP_REFERER is also present for GET requests, but only when the user agent supports it and when it's available (e.g. if the user really accesses mainMenu.php directly then there's no HTTP_REFERER, whether the request is GET or POST).
bmh777Author Commented:
How can you go directly to a page using POST?

I went to a PHP page using my above example and by typing the complete url in my browser, both are GET requests and neither one had a HTTP_REFERER.  I did this for NN 7.1 and IE 6.  When is HTTP_REFERER present for a GET request?
It's present when you click a link or are redirected, but if the user is coming from nowhere before the redirect then there may be no HTTP_REFERER.

Scenario #1

1. User is at
2. User clicks (GET request with HTTP_REFERER set to "")
3. User is redirected to (GET request with HTTP_REFERER still set to "" because of redirection)

Scenario #2

1. User accesses directly (GET request, blank HTTP_REFERER)
2. User is redirected to (GET request, blank HTTP_REFERER)

That's the way redirection works, it itself has nothing to do with whether the request contains a HTTP_REFERER or not.
bmh777Author Commented:
So with that said, how can I detect if a user went straight to the main menu and by-passed the login page?  And,  how can you go directly to a page using POST?
All Courses

From novice to tech pro — start learning today.