Current location: Hot Scripts Forums » Programming Languages » PHP » Need help with detect referer


Need help with detect referer

Reply
  #1 (permalink)  
Old 11-04-06, 08:34 AM
crazytrain crazytrain is offline
New Member
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Need help with detect referer

I am trying to block access to my site from a particular site. The following code works fine but how do I get it to work with more than one link from the site I am blocking.

PHP Code:

// get referrer from _SERVER array

$ref $_SERVER["HTTP_REFERER"];

// look for bad guys!
if ($ref == 'http://site_to_block.com/top10.aspx'

    
//bad referrer detected, exit script
    
print "Access Denied"
    exit;

this link is blocked --> http://site_to_block.com/top10.aspx

but if I add ($ref== 'http://site_to_block.com/top10.aspx', 'http://site_to_block.com/link_from_another_page.aspx')

the script doesn't work. Where am I going wrong?

Last edited by Nico; 11-04-06 at 11:19 AM.
Reply With Quote
  #2 (permalink)  
Old 11-04-06, 09:04 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Try this to block the whole domain instead of each file.

PHP Code:



$site_to_block 
'site_to_block.com'// without www.
$ref parse_url(str_replace('www.'''$_SERVER['HTTP_REFERER']));

if (
$ref['host'] == $site_to_block)
{
    
//bad referrer detected, exit script
    
print "Access Denied"
    exit;

On a sidenote from php.net
Quote:
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
Reply With Quote
  #3 (permalink)  
Old 11-04-06, 09:19 AM
crazytrain crazytrain is offline
New Member
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Perfect! Thanks so much for the help Nico
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto detect page on load surendra PHP 2 04-21-06 10:34 AM
allow blank referer free_dragon PHP 3 02-08-06 08:47 AM
how to detect time inside a file??help!!! LEN2884 C/C++ 2 06-02-05 11:23 PM
JScript to make no menubar and detect keyboard routine weilies Script Requests 0 04-03-04 09:05 PM
Getting referer info lordmerlin PHP 0 01-31-04 08:37 AM


All times are GMT -5. The time now is 05:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.