Padgoi Posted June 10, 2008 Share Posted June 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/109486-tracking-external-referrals-need-a-little-help/ Share on other sites More sharing options...
DarkerAngel Posted June 10, 2008 Share Posted June 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/109486-tracking-external-referrals-need-a-little-help/#findComment-561624 Share on other sites More sharing options...
Padgoi Posted June 10, 2008 Author Share Posted June 10, 2008 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! Link to comment https://forums.phpfreaks.com/topic/109486-tracking-external-referrals-need-a-little-help/#findComment-561625 Share on other sites More sharing options...
DarkerAngel Posted June 10, 2008 Share Posted June 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/109486-tracking-external-referrals-need-a-little-help/#findComment-561628 Share on other sites More sharing options...
Padgoi Posted June 10, 2008 Author Share Posted June 10, 2008 Thanks darkerangel, but again, my php skills are pretty much non-existent. Which instances of /n to I change? All of them? Can you please be a bit more specific, I'd really appreciate it. Thanks. Link to comment https://forums.phpfreaks.com/topic/109486-tracking-external-referrals-need-a-little-help/#findComment-561630 Share on other sites More sharing options...
DarkerAngel Posted June 10, 2008 Share Posted June 10, 2008 :-\ why don't you just add the: <pre> to the start of the file then? or do: <?php $n = '<pre>'.$n.'</pre>'; $fp = fopen($file, "w"); fputs($fp, $n, strlen($n)); fclose($fp); ?> Link to comment https://forums.phpfreaks.com/topic/109486-tracking-external-referrals-need-a-little-help/#findComment-561631 Share on other sites More sharing options...
Padgoi Posted June 10, 2008 Author Share Posted June 10, 2008 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! Link to comment https://forums.phpfreaks.com/topic/109486-tracking-external-referrals-need-a-little-help/#findComment-561636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.