block a referring site?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dankish
Forum Newbie
Posts: 3
Joined: Wed Jan 26, 2005 7:56 pm

block a referring site?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
dankish
Forum Newbie
Posts: 3
Joined: Wed Jan 26, 2005 7:56 pm

Post by dankish »

yes,its to block a referrer...i keep getting spammed in my guestbook from this site.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
dankish
Forum Newbie
Posts: 3
Joined: Wed Jan 26, 2005 7:56 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

thegreatone2176
Forum Contributor
Posts: 102
Joined: Sun Jul 11, 2004 1:27 pm

Post 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
Last edited by thegreatone2176 on Sat Jan 29, 2005 2:45 pm, edited 1 time in total.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

.htaccess roX my SoX ;) (look it up)
Post Reply