Solved

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

Posted on 2004-08-31
5
210 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
  • 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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP temp path missing 4 55
XAMPP 3 68
browser caching 4 77
Apache Issues 9 87
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

828 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