Jump to content

PHP ban IP


dezkit

Recommended Posts

is there a way so that if the ip is 12.123.123.12 that it states a reason

 

<?php
$banned_ip = array();
$banned_ip[] = '12.123.123.12';
$banned_ip[] = '';
$banned_ip[] = '';
foreach($banned_ip as $banned) { 
    $ip = $_SERVER['REMOTE_ADDR'];
    if($ip == $banned){ 
        echo "<br><br><br><br><br><br><br><br><center>
<font size='+2'>You have been banned from this site for ??????.</font>
<br>For further information about your ban, please email us at [email protected]
and remember to include your IP Address
<br><br>Your IP address is ";
        echo $_SERVER['REMOTE_ADDR'];
        exit(); 
    } 
} 
?>

Link to comment
https://forums.phpfreaks.com/topic/98056-php-ban-ip/
Share on other sites

We get what you're saying, what I'm asking is what's wrong with the way you were doing it.  Create either a db table of banned ip addresses, or an array in a php page.  Check if the current ip address is either in that db table or in the array, if it is display an error.  Where are you confused?

Link to comment
https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501735
Share on other sites

Try this:

 

<?php
// Array of ip addresses
$blocked = array("12.123.123.12","1.1.1.1"); // keep adding ip addresses by comma. 1.1.1.1 is an example, feel free to remove it

// Grab users ip address
$ip = $_SERVER['REMOTE_ADDR'];

// Check if ip is supposed to be blocked
if(in_array($ip,$blocked)){
  echo "Spam";
  die();
}

?>

 

Something like that should work

Link to comment
https://forums.phpfreaks.com/topic/98056-php-ban-ip/#findComment-501742
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.