unlimited2009 Posted February 20, 2009 Share Posted February 20, 2009 Hello there, I am in a bit of a muddle. I have a PHP referrers script on my website, the script was made by a guy called Scott Riggs, if anyone is familar with it. Anyway, I'm receiving alot of unwanted fake referrers from websites and would like a solution to this. <?php /* Modified by Scott Riggs at www.cybernetec.com */ $path = '/home/path/public_html/'; // Name of referrer log file $reflog = $path . 'reflog.txt'; // Name of semaphore file $semaphore = $path . 'semaphore.ref'; // Maximum number of referrers to log $maxref = 9; // Domain name of this site (minus "http://vimixx.net") $mydomain = 'yoursite.co.uk'; // From whence did Bunky come? $ref = getenv("HTTP_REFERER"); I was wondering if there's a way to add more URLS to the '$mydomain' string, as this will prevent unwanted fake referrers being mentioned on my website. If anyone could help me with this, as I have tried several ways and I keep getting errors, then it would be much appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/ Share on other sites More sharing options...
Cosizzle Posted February 20, 2009 Share Posted February 20, 2009 Well you could make $mydomain an array to give it more then one... Im confused to what the error is though Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767249 Share on other sites More sharing options...
unlimited2009 Posted February 20, 2009 Author Share Posted February 20, 2009 Would you perhaps like to make a demonstration of that for me and I'll see if works? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767251 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 You do realize that the "HTTP_REFERER" variable is highly un-reliable. Anyone can spoof it, unfortunately. If a spammer (I take it that is the aim of this script to prevent) wants to he just adds it to hist browser and that being the default referrer and wham, he has access. Just noticed it logs it. So you want to add more websites to "not" log. List 2-3 of the websites you do not want to be logged and this is an easy fix. Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767254 Share on other sites More sharing options...
unlimited2009 Posted February 20, 2009 Author Share Posted February 20, 2009 You do realize that the "HTTP_REFERER" variable is highly un-reliable. Anyone can spoof it, unfortunately. If a spammer (I take it that is the aim of this script to prevent) wants to he just adds it to hist browser and that being the default referrer and wham, he has access. Just noticed it logs it. So you want to add more websites to "not" log. List 2-3 of the websites you do not want to be logged and this is an easy fix. I'm not too good with PHP, please show me an example of what to do, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767260 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 So you want to add more websites to "not" log. List 2-3 of the websites you do not want to be logged and this is an easy fix. Maybe if you provide me with the requested information I can help. Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767273 Share on other sites More sharing options...
unlimited2009 Posted February 20, 2009 Author Share Posted February 20, 2009 So you want to add more websites to "not" log. List 2-3 of the websites you do not want to be logged and this is an easy fix. Maybe if you provide me with the requested information I can help. Let's just say blahblah1.com and blahblah2.com, where would that go? And would there be an option to add more? Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767277 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 Since you only posted half the script, here is a rough example. <?php /* Modified by Scott Riggs at www.cybernetec.com */ $path = '/home/path/public_html/'; // Name of referrer log file $reflog = $path . 'reflog.txt'; // Name of semaphore file $semaphore = $path . 'semaphore.ref'; // Maximum number of referrers to log $maxref = 9; // Domain name of this site (minus "http://vimixx.net") $mydomain = array('yoursite.co.uk', 'blahblah.com', 'blahblah2.com'); // From whence did Bunky come? $ref = getenv("HTTP_REFERER"); $log = true; foreach ($mydomain as $domain) { if (stristr($domain, $ref) !== false) { $log = false; break; // exit the loop no need to continue. } } if ($log) { //log to file } Use stristr to test if a domain listed in the array of $mydomain if it is simply set the log to false, exit the loop then use an if to see if you log the referrer to file or not. I do not know how the rest of the script works, but hopefully you can take that idea and implement it on your own. Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767285 Share on other sites More sharing options...
unlimited2009 Posted February 20, 2009 Author Share Posted February 20, 2009 <?php /* Modified by Scott Riggs at www.cybernetec.com */ $path = '/home/pathname/public_html/'; // Name of referrer log file $reflog = $path . 'reflog.txt'; // Name of semaphore file $semaphore = $path . 'semaphore.ref'; // Maximum number of referrers to log $maxref = 15; // Domain name of this site (minus "http://") $mydomain = array('blah1.com', 'blah2.com', 'blah3.com'); // From whence did Bunky come? $ref = getenv("HTTP_REFERER"); $log = true; foreach ($mydomain as $domain) { if (stristr($domain, $ref) !== false) { $log = false; break; // exit the loop no need to continue. } } if ($log) { //log to file } // Cover me. I'm going in. if (($ref) and (!strstr($ref, $mydomain))) { // if there's a referrer, and it's not someone bouncing around this site $ref .= "\n"; // append a line feed $sp = fopen($semaphore, "w"); // open the semaphore file if (flock($sp, 2)) { // lock the semaphore; other processes will stop and wait here $rfile = file($reflog); // read the referrer log into an array if ($ref <> $rfile[0]) { // if this referrer is different from the last one if (count($rfile) == $maxref) // if the file is full array_pop($rfile); // pop the last element array_unshift($rfile, $ref); // push the new referrer onto the front $r = join("", $rfile); // make the array into a string $rp = fopen($reflog, "w"); // open the referrer log in write mode $status = fwrite($rp, $r); // write out the referrer URLs $status = fclose($rp); // close the log } } $status = fclose($sp); // close the semaphore (and release the lock) } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767294 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 // Cover me. I'm going in. if (($ref) && $log) { // if there's a referrer, and it's not someone bouncing around this site $ref .= "\n"; // append a line feed $sp = fopen($semaphore, "w"); // open the semaphore file if (flock($sp, 2)) { // lock the semaphore; other processes will stop and wait here $rfile = file($reflog); // read the referrer log into an array if ($ref <> $rfile[0]) { // if this referrer is different from the last one if (count($rfile) == $maxref) // if the file is full array_pop($rfile); // pop the last element array_unshift($rfile, $ref); // push the new referrer onto the front $r = join("", $rfile); // make the array into a string $rp = fopen($reflog, "w"); // open the referrer log in write mode $status = fwrite($rp, $r); // write out the referrer URLs $status = fclose($rp); // close the log } } $status = fclose($sp); // close the semaphore (and release the lock) } Should do it. Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767301 Share on other sites More sharing options...
unlimited2009 Posted February 20, 2009 Author Share Posted February 20, 2009 // Cover me. I'm going in. if (($ref) && $log) { // if there's a referrer, and it's not someone bouncing around this site $ref .= "\n"; // append a line feed $sp = fopen($semaphore, "w"); // open the semaphore file if (flock($sp, 2)) { // lock the semaphore; other processes will stop and wait here $rfile = file($reflog); // read the referrer log into an array if ($ref <> $rfile[0]) { // if this referrer is different from the last one if (count($rfile) == $maxref) // if the file is full array_pop($rfile); // pop the last element array_unshift($rfile, $ref); // push the new referrer onto the front $r = join("", $rfile); // make the array into a string $rp = fopen($reflog, "w"); // open the referrer log in write mode $status = fwrite($rp, $r); // write out the referrer URLs $status = fclose($rp); // close the log } } $status = fclose($sp); // close the semaphore (and release the lock) } Should do it. Nope, it's still showing my website address as a recent referrer. Here's a copy of the script I found, maybe theres more to do: http://lee-stewart.co.uk/ccount/click.php?id=54 Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767308 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 <?php /* Modified by Scott Riggs at www.cybernetec.com */ $path = '/home/pathname/public_html/'; // Name of referrer log file $reflog = $path . 'reflog.txt'; // Name of semaphore file $semaphore = $path . 'semaphore.ref'; // Maximum number of referrers to log $maxref = 15; // Domain name of this site (minus "http://") $mydomain = array('lee-stewart.co.uk', 'blah2.com', 'blah3.com'); // From whence did Bunky come? $ref = getenv("HTTP_REFERER"); $log = true; foreach ($mydomain as $domain) { if (stristr($domain, $ref) !== false) { $log = false; break; // exit the loop no need to continue. } } // Cover me. I'm going in. if (!empty($ref) && $log) { // if there's a referrer, and it's not someone bouncing around this site $ref .= "\n"; // append a line feed $sp = fopen($semaphore, "w"); // open the semaphore file if (flock($sp, 2)) { // lock the semaphore; other processes will stop and wait here $rfile = file($reflog); // read the referrer log into an array if ($ref <> $rfile[0]) { // if this referrer is different from the last one if (count($rfile) == $maxref) // if the file is full array_pop($rfile); // pop the last element array_unshift($rfile, $ref); // push the new referrer onto the front $r = join("", $rfile); // make the array into a string $rp = fopen($reflog, "w"); // open the referrer log in write mode $status = fwrite($rp, $r); // write out the referrer URLs $status = fclose($rp); // close the log } } $status = fclose($sp); // close the semaphore (and release the lock) } ?> The above is tested and working. Make sure you are not just seeing an old entry an thinking it was newly created. Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767312 Share on other sites More sharing options...
unlimited2009 Posted February 20, 2009 Author Share Posted February 20, 2009 Check out: http://lee-stewart.co.uk/referrers.php and you can see that it's showing the same web address at the top? Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767318 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 Sorry, I tested the above with a bad string to test with. This should work (I had the params for stristr reversed.) <?php /* Modified by Scott Riggs at www.cybernetec.com */ $path = '/home/pathname/public_html/'; // Name of referrer log file $reflog = $path . 'reflog.txt'; // Name of semaphore file $semaphore = $path . 'semaphore.ref'; // Maximum number of referrers to log $maxref = 15; // Domain name of this site (minus "http://") $mydomain = array('lee-stewart.co.uk', 'blah2.com', 'blah3.com'); // From whence did Bunky come? $ref = getenv("HTTP_REFERER"); $log = true; foreach ($mydomain as $domain) { if (stristr($ref, $domain) !== false) { // fixed this, they were reversed. $log = false; break; // exit the loop no need to continue. } } // Cover me. I'm going in. if (!empty($ref) && $log) { // if there's a referrer, and it's not someone bouncing around this site $ref .= "\n"; // append a line feed $sp = fopen($semaphore, "w"); // open the semaphore file if (flock($sp, 2)) { // lock the semaphore; other processes will stop and wait here $rfile = file($reflog); // read the referrer log into an array if ($ref <> $rfile[0]) { // if this referrer is different from the last one if (count($rfile) == $maxref) // if the file is full array_pop($rfile); // pop the last element array_unshift($rfile, $ref); // push the new referrer onto the front $r = join("", $rfile); // make the array into a string $rp = fopen($reflog, "w"); // open the referrer log in write mode $status = fwrite($rp, $r); // write out the referrer URLs $status = fclose($rp); // close the log } } $status = fclose($sp); // close the semaphore (and release the lock) } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767324 Share on other sites More sharing options...
unlimited2009 Posted February 20, 2009 Author Share Posted February 20, 2009 Thanks, that seems to have worked. I'm hoping websites such as edgney.co.cc and elevatorney.co.cc do not show up on the referrers list, as they have been a major pain for me, thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/146145-solved-php-referrers-script-string-please-help/#findComment-767328 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.