Jump to content

Referrers Script tiny problem


respected

Recommended Posts

Hello I have a referrers script that I use on my website. The thing is, it only blocks out one URL so that it doesn't appear on the referrers list and that is ofcourse my site.
I have tried lots of ways in order to allow the script to take in as many URLs because they're certain websites I do not want to be listed.

Can anyone help me? The troubled php coding I have is with reflog.php:-

[code]<?php
/*
  Modified by Scott Riggs
  at www.cybernetec.com
*/
$path = '/home/blabla/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 = 6;

// Domain name of this site (minus "http://www.")
$mydomain = 'site1.com';

// From whence did Bunky come?
$ref = getenv("HTTP_REFERER");

// Cover me. I'm going in.

if (($ref) and (!strstr($ref, $mydomain, $mydomain2))) {        // 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)
}
?>[/code]
I've tried adding as many lines as I could like this:

[code]
$mydomain = 'site1.com';
$mydomain2 = 'site2.com';
$mydomain3 = 'site3.com';[/code]and adding elseifs under each line, like this:-

[code]if (($ref) and (!strstr($ref, $mydomain))) {
elseif if (($ref) and (!strstr($ref, $mydomain2))) {
elseif (($ref) and (!strstr($ref, $mydomain3))) {
[/code]But that doesn't seem to work. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/27241-referrers-script-tiny-problem/
Share on other sites

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.