Solved

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

Posted on 2004-08-31
5
211 Views
Last Modified: 2010-03-04
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?
0
Comment
Question by:bmh777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:chipple
ID: 11949050
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).
0
 

Author Comment

by:bmh777
ID: 11949204
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?
0
 
LVL 4

Expert Comment

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

Author Comment

by:bmh777
ID: 11949352
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?
0
 
LVL 4

Accepted Solution

by:
chipple earned 75 total points
ID: 11949392
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("www.myDomain.com",80);
fwrite($fp,'POST /mainMenu.php HTTP/1.0
Host: www.myDomain.com'."\n\n");
$buf = "";
whlie (!feof($fp)) $buf .= fred($fp,0x1000);
fclose($fp);

Good luck.
0

Featured Post

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question