Link to home
Start Free TrialLog in
Avatar of bmh777
bmh777

asked on

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:

header("Location: http://www.myDomain.com/mainMenu.php");

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.

Thanks,
bmh
ps. Can this be done w/o using cookies?
Avatar of chipple
chipple

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).
Avatar of bmh777

ASKER

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 https://www.experts-exchange.com/
2. User clicks http://www.myDomain.com/RedirectToMainMenu.php (GET request with HTTP_REFERER set to "https://www.experts-exchange.com/")
3. User is redirected to http://www.myDomain.com/mainMenu.php (GET request with HTTP_REFERER still set to "https://www.experts-exchange.com/" because of redirection)

Scenario #2

1. User accesses http://www.myDomain.com/RedirectToMainMenu.php directly (GET request, blank HTTP_REFERER)
2. User is redirected to http://www.myDomain.com/mainMenu.php (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.
Avatar of bmh777

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of chipple
chipple

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial