Jump to content

[SOLVED] PHP referrers script string - Please help!


unlimited2009

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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)

}

?>

Link to comment
Share on other sites

// 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.

 

Link to comment
Share on other sites

// 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

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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)
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.