Jump to content

Tracking External Referrals, need a little help


Padgoi

Recommended Posts

Ok, so I have this small script which tracks external referrals for my site:

 

<?

$domain = 'YourDomain.com';
$file = "referral_tracker.txt";

$ref = $_SERVER['HTTP_REFERER'];

$thisDomain = strpos($ref, $domain);

if ($thisDomain === false) {
if ($ref == '') {
$ref = 'UnknownLocation';
}
$saveRef = true;
} else {
$saveRef = false;
}

if ($saveRef == true) {

$to = $ref;

$fp = fopen($file, "r");
$gf = fread($fp, filesize($file));
fclose ($fp);

$arr = explode("\n\n", $gf);
$n = "";

foreach ($arr as $line) {
$line = trim($line);

if ($line != "") {
$sub = explode(" ", $line);

if ($to == $sub[0]) {
$tracked = true;
$sub[1]++;
}
$n .= $sub[0] . " " . $sub[1] . "\n\n";
}
}

if ($tracked != true) {
$n .= $to . " 1\n\n";
}

$fp = fopen($file, "w");
fputs($fp, $n, strlen($n));
fclose($fp);

}
?>

 

This script works fine, but it just saves the referrals into a text file and when I access the text file, it simply lists the referrals. I changed the file that referrals get tracked to referrals.html, which is fine, but now it's just saving them in one long line instead of skipping a space between each referral.  I did this because I wanted to add a little css which I did, but can anyone give me a little help so that the script skips a line between each referral listed?  Thanks in advance.

Either change '\n' to '<br />' or have the html tag '<pre>' before the listing.

 

HTML Considers line breaks as white space and does not preserve white space unless it is enclosed in the '<pre>' tag which tells the html document that the text contained is pre-formatted.

Thanks, but can you be a bit more specific please?

 

I see one line like this:

$arr = explode("\n\n", $gf);

 

and I see another line like this:

$n .= $sub[0] . " " . $sub[1] . "\n\n";

 

and i see a third line like this:

$n .= $sub[0] . " " . $sub[1] . "\n\n";

 

and I see a fourth line like this:

$n .= $to . " 1\n\n";

 

Which one do I change and what exactly do I change it to?  Sorry for the questions, but my php skills are pretty non-existent.  Thanks!

 

 

I'm sorry the post stripped my HTML Tags here's my post again...

Either change '\n' to '<br />' or have the html tag '<pre>' before the listing.

HTML Considers line breaks as white space and does not preserve white space unless it is enclosed in the '<pre>' tag which tells the html document that the text contained is pre-formatted.

Ok dark, I got it working, thanks. 

 

Another issue came up though.  The css I added keeps getting deleted every time a new referral is added.  It seems I have to add the css to the actual script and not the html file.  Could you help me with one other thing?

 

I want to add this css to the script so that it looks a bit more organized:

 

<div style='border: 3px dotted #0af; font-family: Tahoma; padding: 20px; padding-top: 0; font-size: 12px; background-color: #fafafa; margin: 50px;'><p><h2>REFERERERS (NEWEST FIRST)</h2></p>

 

I really appreciate your help, my friend.  Thank you!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.