Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to block domains without blocking other domains on same IP address

Status
Not open for further replies.

adayinthelife

Programmer
Jan 28, 2005
4
US
Hi,

I am having a problem getting my code to execute what is needed. It is sort of complex, but I think I have most of it down. Though, when I test it, it does not seem to work as I want it to.

Let me explain a bit, to give a little more info here:

I have a search engine, and as a Pay Per Click Search Engine owner, I think it is an invaluable tool to be able to block domain names that have abused, or incentivize traffic, etc...

Anyway, I have gotten the programming part done that allows me to put in the domain name and store it in a text file for later reading. That, I do not think is the problem.

But, what I want to happen, is to later check that data file against the referrering URL to my site. I use the $ENV{HTTP_REFERER} environmental variable to compare it to the domain I have set to be blocked like this:

################
Code:
[COLOR=maroon]# keyword has been clicked to initiate search to return 
# results for that keyword clicked...

# this is the beginning of that process to be carried out
# where I set up the argument...[/color]

[b]sub dosearch {
    my ($begin, $howmany, $thing, $paidname, $freename) = @_;[/b]
    [COLOR=maroon]# below line is not related to the problem of the
    # domains being banned, but is before where argument for
    # domain matching is made, just so as to not confuse 
    # anymore so than I may have already :-)
    [/color]
    [b]require 'include/affapproval.cgi'; &checkaff($username);
    if ($username ne '') { &idcheck; }[/b]
    
   [COLOR=maroon] # here is where I set up to match domain.
[/color]
    [b]if (($ENV{HTTP_REFERER}) ne '') { &domcheck; }[/b]
[COLOR=maroon]
    # then goes through several routines for to search 
    # for keywords to bring back results, but if the above
    # arguments were returned as being flagged, it is 
    # supposed to deny completing the search and returning
    # results. So, getting to the next part...
[/color]

[b]sub domcheck {[/b]
    [COLOR=maroon]
    # $domfile contain the domains to check against[/color]
    [b]$domfile = "$dir$data_dir/domfile.txt";[/b] 
    
   [COLOR=maroon] # referring to the environmental variable (HTTP_REFERER)
    # as the $domain below.[/color]
    [b]$domain = $ENV{HTTP_REFERER};[/b]
    
    [COLOR=maroon]# stripping extra components from referring url...[/color]
    [b]@url = split(/\/\//, $domain);
    @url2 = split(/\//, $url[1]);[/b]
    
    [COLOR=maroon]# arrive at final value to match against my data file[/color]
    [b]$dom = $url2[0];[/b]
  
    [COLOR=maroon]# put debug code in here to make sure it was stripping
    # HTTP_REFERER properly and it does match the exact 
    # domain I had meant to match - ex:  [URL unfurl="true"]www.domain.com[/URL]
    # stripped out of 
    # [URL unfurl="true"]http://www.example.com/pages/search.php?ref=green[/URL] or
    # whatever it may be - but strips to just [URL unfurl="true"]www.domain.com[/URL]
    # and I confirmed it through my debug output[/color]
    [b]if ($settings{'debug'}) { print DEBUG "\$dom - $dom\n"; }[/b]

    [COLOR=maroon]# now checking file against domain name[/color]
    [b]open(FILE,"$domfile"); 
    flock(FILE,LOCK_SH|LOCK_NB); 
    flock(FILE,LOCK_SH);
    while (<FILE>) {[/b]
      [COLOR=maroon]# is supposed to redirect traffic if domain matches[/color]
        [b]if ($_ =~ /^$dom$/) {
	  print "Content-type: text/html\n\n";
   	  print qq~<html><head><meta http-equiv="Refresh" content="10; URL=http://yahoo.com/"><title>Domain Not Accepted</title></head><body><p>.explanation as to why they are going to be redirected</p></body></html>~; 		
        exit;
        }
    }
    close(FILE);
}[/b]
##################

Sorry for the rather lengthy description, but shouldn't this work, if domain is matched to the $ENV{HTTP_REFERER} ?

I am not sure what else can be done in order to be able to get it to work properly. Would appreciate any feedback, ideas, etc - or alternate solutions to getting domains blocked, so that, only the domain name cannot access this part of the site, whereas, still, if there were 100 other sites on that same IP address of the domain in question, they would not have a problem accessing the site if they too were not also blocked.

Thanks to anyone who took the time to read this :)

Mike
 
Mike,

is this a click fraud thing?

--Paul


cigless ...
 
Well, a click fraud thing, yes, but is also more of a means to control better the traffic accessing and "allowed" to access the part of the site whereby the Paid for/sponsored results are placed because of the initial query on a keyword.

This is necessary for several reasons, but among the most important is to disallow domains to access the site who have demonstrated abuse of clicking (incentivized, or affiliates who's sites were never approved, people who send bot traffic from a certain domain) as well as to honor the request of upstream partners who have asked to ban certain domains.

So, what I would like it to do - is to match that domain, and then, if it is a direct match, to redirect the traffic away from the paid results.

Hope this makes a little more sense.

Regards,

Mike
 
So, err, what seems to be the problem?

Are you saying that it's failing to match HTTP_REFERER with lines in the text file that you think ought to match? Cos you haven't actually said anything of the kind.

If so, you probably need to [tt]chomp()[/tt] the lines you read from the file to remove any trailing CR or LF characters.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Hmmm, I will try the chomp() suggestion, and will let you know how it works out. Thanks for the feedback.

Mike
 
Just want to say thanks for the little push there Chris! Got it working :)

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top