Make ip block function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FiremanSAM

    Make ip block function

    Hai all,

    I would make a ip block script for my site. The blocked ip are stored in a
    file.
    I have made the following script. Why does this not work. The file entries
    must be stored in a array and after that i must check all the fields in the
    array. Please help...

    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $bestand = "ipblock.tx t";
    $open = fopen($bestand, "r");

    $iparray = file ($open);

    $n = 0;

    while ($n < count($iparray) ) {
    if ($iparray[$n] == $ip) {
    print ("NOT");
    else {
    print ("YES");
    $n++;
    }
    }

    ?>

    FiremanSAM


  • Pedro

    #2
    Re: Make ip block function

    FiremanSAM wrote:[color=blue]
    > I would make a ip block script for my site. The blocked ip are stored in a
    > file.
    > I have made the following script. Why does this not work. The file entries
    > must be stored in a array and after that i must check all the fields in the
    > array. Please help...
    >
    ><?php
    > $ip = $_SERVER['REMOTE_ADDR'];
    > $bestand = "ipblock.tx t";
    > $open = fopen($bestand, "r");
    >
    > $iparray = file ($open);[/color]

    $iparray = file ($besthand);
    // and do not fopen() it



    --
    I have a spam filter working.
    To mail me include "urkxvq" (with or without the quotes)
    in the subject line, or your mail will be ruthlessly discarded.

    Comment

    • Randell D.

      #3
      Re: Make ip block function


      "FiremanSAM " <firemansam@co. uk> wrote in message
      news:%DCeb.8024 $P51.17060@amst wist00...[color=blue]
      > Hai all,
      >
      > I would make a ip block script for my site. The blocked ip are stored in a
      > file.
      > I have made the following script. Why does this not work. The file entries
      > must be stored in a array and after that i must check all the fields in[/color]
      the[color=blue]
      > array. Please help...
      >
      > <?php
      > $ip = $_SERVER['REMOTE_ADDR'];
      > $bestand = "ipblock.tx t";
      > $open = fopen($bestand, "r");
      >
      > $iparray = file ($open);
      >
      > $n = 0;
      >
      > while ($n < count($iparray) ) {
      > if ($iparray[$n] == $ip) {
      > print ("NOT");
      > else {
      > print ("YES");
      > $n++;
      > }
      > }
      >
      > ?>[/color]

      You don't need to use fopen - instead

      $iparray=file($ bestand);

      Secondly, instead of using the while loop, why not use something like
      array_search() which would probably be more performance effective?


      Comment

      Working...