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 webmaster@xx.com
and remember to include your IP Address
<br><br>Your IP address is ";
        echo $_SERVER['REMOTE_ADDR'];
        exit(); 
    } 
} 
?>

Link to comment
Share on other sites

i dont think you guys get what im saying  :P

 

i am saying that if the person on the computer has a ip banned from the site, so it echo's a reason why he was banned

 

like

 

    if($ip == $banned){

        echo "spamming";

        exit();

    }

}

 

 

or something

Link to comment
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
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
Share on other sites

nevermind, i got it :) thanks alot!

 

<?php

$spam = array("xxxxx","xxxxx");
$other = array("xxxxx","xxxxx");

$ip = $_SERVER['REMOTE_ADDR'];

if(in_array($ip,$spam)){
  echo "Spam";
  die();
}
if(in_array($ip,$other)){
  echo "Other";
  die();
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.