Help With Php Script

Discussion in 'PHP' started by hulk, Nov 23, 2006.

  1. #1
    Trying to implement the following php script that i found at php.net. My question how to mod the following script so that it redirects the users to index.php page if it is found that the ip is black listed.

    $result=Array();
    $dnsbl_check=array("bl.spamcop.net",
    "list.dsbl.org",
    "sbl.spamhaus.org");
    if ($ip)
    {
    $quads=explode(".",$ip);
    $rip=$quads[3].".".$quads[2].".".$quads.".".$quads[0];
    for ($i=0; $i<count($dnsbl_check); $i++)
    {
    if (checkdnsrr($rip.".".$dnsbl_check[$i].".","A"))
    {
    $result1[]=Array($dnsbl_check[$i],$rip.".".$dnsbl_check[$i]);
    }
    }
    }
    aeroguy is online now Add to aeroguy's Reputation Report Post Edit/Delete Message
     
    hulk, Nov 23, 2006 IP
  2. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #2
    if you havn't produced any HTML output yet, you can use

    
    header("Location:/path/to/new/location.php");
    
    Code (markup):
     
    drewbe121212, Nov 23, 2006 IP
  3. hulk

    hulk Guest

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    where exactly would i place that with in the code?
     
    hulk, Nov 23, 2006 IP
  4. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Something like :
    
    <?php
    $ip = getenv("REMOTE_ADDR");
    function is_blacklisted($ip) {
       $dnsbl_check=array("bl.spamcop.net",
                           "list.dsbl.org",
                           "sbl.spamhaus.org");
       if ($ip) {
           $quads=explode(".",$ip);
           $rip=$quads[3].".".$quads[2].".".$quads[1].".".$quads[0];
           for ($i=0; $i<count($dnsbl_check); $i++) {
               if (checkdnsrr($rip.".".$dnsbl_check[$i],"A")) {
                   $listed.=$dnsbl_check[$i]." ";
               }
             }
           if ($listed) { return $listed; } else { return FALSE; }
       }
    }
    $j=is_blacklisted($ip);
    if ($j)
    {
    header("Location:/index.php");
    }
    else {
    //do something else 
    }
    ?>
    
    PHP:
     
    maiahost, Nov 24, 2006 IP
  5. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #5
    ^^^ Exactly. You just need to do it when the ip is registered as a blacklisted ip. If that doesn't work, IE you get an error message that sais "HEADERS ALREADY SENT..." something like that, you can use this code instead.

    It is through javascript, but it still works.
    
    echo "<script language="javascript">location.href='/path/to/file/file.php';</script>";
    
    PHP:
     
    drewbe121212, Nov 24, 2006 IP
  6. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #6
    BTW this wont work anyway :

    
    header("Location:/index.php");
    
    PHP:
    The correct one is

    
    header("Location: /index.php");
    
    PHP:
    Check the space between : and / :)
     
    Nikolas, Nov 24, 2006 IP
  7. php_daemon

    php_daemon Active Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #7
    As a side note, according to HTTP 1.1 specification, the url should be absolute.
     
    php_daemon, Nov 24, 2006 IP
  8. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #8
    Yeah that's right, but it will work with a relative url in any browser anyway :)
     
    Nikolas, Nov 24, 2006 IP
  9. php_daemon

    php_daemon Active Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #9
    Indeed it will, just mentioned that for standard freaks out there. :)
     
    php_daemon, Nov 24, 2006 IP
  10. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #10
    well I did test that before I posted it so ... what's your verdict ? :)
     
    maiahost, Nov 24, 2006 IP
  11. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #11
    The verdict is go with what works! :)
     
    drewbe121212, Nov 24, 2006 IP