1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

wap browser detection for spider trap

Discussion in 'PHP' started by classifieds, Aug 9, 2005.

  1. #1
    I'm trying to update my badbot/spider trap so that it will ignore the Google wap browser .

    I'm want to grab the remote IP and search an array to see it matches one on my list.

    The code below works for text strings (UA Strings) but not for IP addresses in x.x.x.x format. If anyone has some advice on how this should be performed I would appreciate it.

    As you can tell I can barely spell php .

    -jay

    .

    <?php
    
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    $ip = $_SERVER['REMOTE_ADDR'];
     
    function checkforWap(&$a_v){
      foreach($a_v as $v){
        if(strpos($ua,$v)!==false) return 1;
      }
      return 0;
    }
    
    $a_ip = array(
    '68.1.1.1',
    '67.10.15.12',
    '68.233.25.25',
    );
    
    if (checkforWap($a_ip) )
      {
      print "This IP " . $ip . " matched";
      }
    else {
      print( "This IP  " . $up . " did not match" );
      }
    
    ?>
    
    Code (markup):
     
    classifieds, Aug 9, 2005 IP
    SERPalert likes this.
  2. Ned

    Ned Active Member

    Messages:
    402
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    78
    #2
    
    function check_ip($ip_list,$ip)
    {
    
    
    	foreach($ip_list AS $key=>$value)
    	{
    	     	if($value == $ip)
    	     	{
    			$match = "1";
    	     	};
    	};
    
    	if($match == "1")
    	{
    		return "TRUE";
    	}
    	else
    	{
    		return "FALSE";
    	}
    }
    
    
    $ip = $_SERVER['REMOTE_ADDR'];
    
    $ip_list = array(
    '68.1.1.1',
    '67.10.15.12',
    '68.233.25.25',
    );
    
    if(check_ip($ip_list,$ip) == "TRUE")
    {
    	echo "This IP: ".$ip." is in the list";
    }
    else
    {
    	echo "This IP: ".$ip." is NOT in the list";
    };
    
    Code (markup):
    ^^^ should work.
     
    Ned, Aug 9, 2005 IP
    classifieds and plarkin like this.
  3. classifieds

    classifieds Sopchoppy Flash

    Messages:
    825
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    150
    #3
    Thanks Ned!

    It seems to work. I'll integrate it into the trap and find out!

    -jay
     
    classifieds, Aug 9, 2005 IP