umbregachoong
umbregachoong

Reputation: 349

trying to write HTTP_REFERER to referer.txt but it's not working

I have several questions. I working within Joomla. I am trying to use this php code to write the referrer to referer.txt but I cannot find 'referer.txt' anywhere in joomla:

<?php 
$referer = get_en("HTTP_REFERER");
if($referer){
$fp=fopen("referer.txt","a")||die("Could not open referer file!");
fwrite($fp,$referer);
fclose($fp);
}
?>

The page on staging does not throw any errors in firebug however.

The bosses want a record of referrers to a specific page ( I am using this specific page as a test. It is not the target page).

My questions are:

  1. If the above code is not failing, where the heck could referer.txt be in a joomla system?

  2. Is there another way of doing this? For example, this page http://www.webvanta.com/post/248869-using-referrer-urls-to-better-understand suggest using javascript to build cookies to track referrers, and this site http://webdesign.about.com/cs/loganalysistools/a/aaloganalysis.htm suggests using web logs and log analysis tools.

What is the best way to do this?

Upvotes: 0

Views: 1009

Answers (1)

newfurniturey
newfurniturey

Reputation: 38436

The first line, $referer = get_en("HTTP_REFERER"); is using get_en(), but the built-in function is getenv().

Another way to access the current user's referrer would be through the $_SERVER['HTTP_REFERRER']; parameter - though according to the documentation this is the same as using getenv().

A server-side method to track the referrers would be to parse the access_log files created by Apache. These logs will offer you request dates, request types (GET, POST, etc), files, query strings, IPs, UserAgents, and a slew of other informative parts.

Regarding where the referer.txt file is being stored, you should open it using an absolute path. You can use $fp=fopen($_SERVER['DOCUMENT_ROOT'] . '/referer.txt', 'a');, or set a custom path such as $fp=fopen("/tmp/referer.txt", 'a');.

Upvotes: 2

Related Questions