...

View Full Version : Referrers Script tiny problem



Respected
11-10-2006, 12:26 AM
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:-


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


I've tried adding as many lines as I could like this:



$mydomain = 'site1.com';
$mydomain2 = 'site2.com';
$mydomain3 = 'site3.com';

and adding elseifs under each line, like this:-


if (($ref) and (!strstr($ref, $mydomain))) {
elseif if (($ref) and (!strstr($ref, $mydomain2))) {
elseif (($ref) and (!strstr($ref, $mydomain3))) {


But that doesn't seem to work. Any ideas?

gunman
11-10-2006, 10:27 AM
Problem is in flock when it first meet condition it locks file and execute commands, but after that you forgot to unlock file and because of that it just add one url.

Respected
11-11-2006, 05:30 PM
Thank you but that did not make one bit of sense. What I need is someone to fix the problem. Not forgetting to speak in lehman terms. Thanks.

Respected
11-18-2006, 06:19 PM
Is everyone dead on bere because I'm getting no answers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum