Page 1 of 1

block a referring site?

Posted: Wed Jan 26, 2005 7:58 pm
by dankish
how do i block a site,not an IP from having access to my site?


Code: Select all

$referer = $_SERVERїHTTP_REFERER];
if ($refer=="0.0.0.0") Header("Location: http://www.google.com");
isnt working

Posted: Wed Jan 26, 2005 8:56 pm
by feyd
blocking a site? Your code appears to try to block a referrer. Referral information is optional for a browser to send, and as such, cannot be trusted to exist.

Posted: Wed Jan 26, 2005 10:38 pm
by dankish
yes,its to block a referrer...i keep getting spammed in my guestbook from this site.

Posted: Wed Jan 26, 2005 10:44 pm
by feyd
provided the referrer is set, you can use parse_url() to break out the domain name, and a string function like strpos() to check if the domain is them..

Posted: Wed Jan 26, 2005 10:46 pm
by dankish
sorry i dont know php...can you help me with it ?

$referer = $_SERVER[HTTP_REFERER];
if ($refer=="www.blockedsite.com") Header("Location: http://www.google.com");

? i dont get it

Posted: Wed Jan 26, 2005 10:47 pm
by feyd

Posted: Sat Jan 29, 2005 2:38 pm
by thegreatone2176
i believe an easier way to do this would be to check to make sure the referer is from your guestbook page

i used this for my guestbook

Code: Select all

if (!empty($_POSTї'username']) && !empty($_POSTї'message'])){ 
$ref = $_SERVERї"HTTP_REFERER"];
if ($ref != "www.bluelightningblade.com/guestbook" || $ref != "www.bluelightningblade.com/guestbook/index.php"){
echo "Invalid Referer";
die;
}
}
it first checks if the username and message is sent because if its not they page needs to be accessed so people can post

then if they are posted it checks to make sure they came from where the form is submitted

Posted: Sat Jan 29, 2005 2:42 pm
by Joe
.htaccess roX my SoX ;) (look it up)