Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with getenv("HTTP_REFERER")

Status
Not open for further replies.

k4ghg

Technical User
Dec 25, 2001
191
US
I wrote a php script to determine when folks have visited a page, where they came from and to write the information to a text page. When I test the script it works fine, but, after 24 hours when I check the text file (CHMOD 666) only the date is recorded. Below is the script and an example of the test file data. Can anyone see what I am doing wrong. Thanks... Ronnie

$ref = getenv("HTTP_REFERER");
$ref = $ref . "\r\n";
$dte = date("d/m/y : H:i:s", time());
$dtf = $dte . " ";
$fp = fopen("countlog.db", "a+");
fwrite($fp, $dtf);
fwrite($fp, $ref);
fclose($fp);

File Data:
24/08/11 : 12:16:31
24/08/11 : 12:17:40
24/08/11 : 12:44:19
24/08/11 : 13:13:53
24/08/11 : 13:14:18
24/08/11 : 13:32:36 24/08/11 : 14:04:12
24/08/11 : 14:43:55
24/08/11 : 14:54:39
 
HTTP_REFERER is only set when the browser sends the referer data to the server. Many browsers, including Opera, Firefox, Chrome and Safari do not by default report referers.

Could this be what you're seeing?




Want to ask the best questions? Read Eric S. Raymond's essay "How To Ask Questions The Smart Way". TANSTAAFL!
 
Thanks for getting back to me. Although, I would think that most referrals would be via a browser, I am not certain what I am seeing and when I checked this morning I had about 30 dates and only one referral. Is there a different PHP function to capture the referral site or something similar? Thanks... Ronnie
 
As has been mentioned, there is no guarantee the referrer will be set in any circumstance, and more often than not browsers won't send it. What you are seeing is that effect, the fact that the value is optional to be set and in many cases is not set at all.

So your script obviously has no value to use to store in your file.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks, what would be the solution? Is there away to track visitors and were they came from?
 
Not unless you have all links set with a parameter.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks again. Does "set with parameter" mean http\\: where item=xyz is the parameter? It was interest I tried using some $_SERVER[... functions and discovered that the hits without information were all Google bot visits. Thanks... Ronnie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top