Deprecated Function eregi in php script

Discussion in 'PHP' started by moath11, Jul 28, 2014.

  1. #1
    i'm getting this error when for this php script , this script is to block multi ip address

    Deprecated: Function eregi() is deprecated in C:\xampp\htdocs\clients\block.php on line 11

    <?php
    // array's of banned IP addresses
    $bannedIP = array("^22.22.*.*","^11.11.*.*");if(in_array($_SERVER['REMOTE_ADDR'],$bannedIP)){// this is for exact matches of IP address in array
    header('HTTP/1.0 404 Not Found');exit();}else{// this is for wild card matchesforeach($bannedIP as $ip){if(eregi($ip,$_SERVER['REMOTE_ADDR'])){
    header('HTTP/1.0 404 Not Found');exit();}}}

    ?>
    how to fix that ?
     
    Solved! View solution.
    moath11, Jul 28, 2014 IP
  2. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #2
    Try using preg_match() instead of eregi()
     
    malky66, Jul 28, 2014 IP
  3. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    please fix that code
     
    moath11, Jul 28, 2014 IP
  4. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #4
    Like I said, just use preg_match instead of eregi, eregi is deprecated as of php5.3
     
    malky66, Jul 28, 2014 IP
  5. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    i did what you say and got this output

    <?php
    // array's of banned IP addresses
    $bannedIP = array("^22.22.*.*","^11.11.*.*");if(in_array($_SERVER['REMOTE_ADDR'],$bannedIP)){// this is for exact matches of IP address in array
    header('HTTP/1.0 404 Not Found');exit();}else{// this is for wild card matchesforeach($bannedIP as $ip){if(preg_match($ip,$_SERVER['REMOTE_ADDR'])){
    header('HTTP/1.0 404 Not Found');exit();}}}
    ?>


    Warning: preg_match(): No ending delimiter '^' found in C:\xampp\htdocs\clients\block.php on line 11
     
    moath11, Jul 28, 2014 IP
  6. #6
    Sorry, I forgot the delimiter, try this
    $bannedIP = array("^22.22.*.*","^11.11.*.*");if(in_array($_SERVER['REMOTE_ADDR'],$bannedIP)){// this is for exact matches of IP address in array
    header('HTTP/1.0 404 Not Found');exit();}else{// this is for wild card matches
    foreach($bannedIP as $ip){if(preg_match('/' . $ip . '/',$_SERVER['REMOTE_ADDR'])){
    header('HTTP/1.0 404 Not Found');exit();}}}
    Code (markup):
     
    malky66, Jul 28, 2014 IP
  7. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    Thank you, worked
     
    moath11, Jul 28, 2014 IP
  8. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    hmm
    srry to say that
    it's not worked on the second server

    Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\AppServ\www\clients\block.php on line 11
     
    moath11, Jul 28, 2014 IP