[nycphp-talk] Returning users from whiniest they came
Daniel Convissor
danielc at analysisandsolutions.com
Fri Jul 11 10:13:22 EDT 2008
Hi Paul:
You misunderstand what http referer does. In addition, be careful of
what some other folks have posted in this thread, they're
misunderstanding your situation, so may confuse you further.
Here are several key points:
* it is set by the browser
* it gets sent in the HTTP headers when requesting a page
* it indicates the URI a hyperlink was found on
Let's say a browser is on Page A. Page A has a link to Page B. When the
user clicks the link to Page B, the browser will put the URI of Page A
into the referer header.
Then, when the person is on Page B they click a link for Page C, the
browswer will put the URI of Page B into the header/request for Page C.
So note that it contains the page that referred the _current_ request.
As others indicated earlier, if you want to know the place someone
entered your site, you need to capture that on the first page they hit.
Something _like_ this:
// Make sure session_start() was called already.
if (!isset($_SESSION['source'])) {
/*
* This is the first hit this person has made to your site
* DURING THIS SESSION. So if you don't manage things right
* this could be a value from an earlier visit.
*/
if (empty($_SERVER['HTTP_REFERER'])) {
// Either not sent or person typed in the URI directly.
$source = false;
} else {
// They clicked a link to get here.
// Make sure it is safe.
$source = $_SERVER['HTTP_REFERER'];
$source = preg_replace('/[^!#-9:;=?-Z_a-z~]/', '', $source);
}
$_SESSION['source'] = $source;
}
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list