a small function (ban ip)

Discussion in 'PHP' started by johnlaiz, Mar 29, 2006.

  1. #1
    because i want to ban some ip start from
    123.

    so i write this function, hope can help someone
    or someone give me more suggestion..:)

    
    function banip($ip_address)
    {
            include('banip.php'); 
    	foreach ($ipaddress as $ban_ip)
    	{
    		if (preg_match("/^$ban_ip/", $ip_address)) 
    		{
    			//header('location: http://somewhere.com');
                           // or anything you want!
    			die();
    		}
    	}
    
    }
    
    
    banip.php
    $ipaddress[]='123.';   // ban all start from 123.
    $ipaddress[]='123.123.'; // ban all start from 123.123
    $ipaddress[]='123.123.123.'; // ban all start from 123.123.123
    $ipaddress[]='123.123.123.123'; // ban 123.123.123.123
    
    Code (markup):
     
    johnlaiz, Mar 29, 2006 IP
  2. Slapyo

    Slapyo Well-Known Member

    Messages:
    266
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    You could just deny them using .htaccess and you won't have to use PHP.
     
    Slapyo, Mar 30, 2006 IP
  3. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3

    But it's not the .htaccess forum! :p

    Some people can't use htaccess as well.

    -the mole
     
    themole, Mar 30, 2006 IP
  4. Psychotomus

    Psychotomus Guest

    Messages:
    427
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $ipaddress[]='123.'; // ban all start from 123.
    $ipaddress[]='123.123.'; // ban all start from 123.123

    complicated at first. i wrote a vb program for a port scanner starting from certain IP's. This will be like 100 lines of code or I would code it for you =) unless your willing to pay.
     
    Psychotomus, Mar 30, 2006 IP
  5. Slapyo

    Slapyo Well-Known Member

    Messages:
    266
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Oh I know that, but maybe they weren't aware they could do it with the .htaccess file.

    If you are using PHP you should check $_SERVER['REMOTE_ADDR'] for the IP address of the person viewing the page.
     
    Slapyo, Mar 31, 2006 IP