Jump to content

Ip ban script not working


sith717

Recommended Posts

This script I made is not working.

 

Please tell me what is wrong.

 

--

ban.php - page

 

<?php

//Id of input box
$IP = Trim(stripslashes($_POST['address'])); 

//This it to log on the website
$mes     .= 'Ip'.$IP."\n<br>";

//Log to a file
$file = "ban.txt";
$fh = fopen($file, "a");
fwrite ($fh, "$mes\n");
fclose($fh);

?>

Ip has been banned!

 

banip.php - page

 

<center>
<FORM action="ban.php" method="post">
    <P>
    <LABEL for="firstname">Ip Address </LABEL>
<br>
              <INPUT type="text" id="address"><BR>
    <INPUT type="submit" value="Send">
    </P>
</FORM>
</center>

 

banned.php - page

 

<?php

$filename = "ban.txt"; //Set File Name
$error = "You have been banned!";
$ips = file($filename); //Load File into Array ips

foreach ($ips as $banned_ip) { //Loop through Ips and check if they match yours

$yourip = $_SERVER['REMOTE_ADDR']; // Store your ip into $yourip

   if ($yourip == $banned_ip){

     echo "$error";

     exit;    

}
}
?>

Text if your not banned

 

Link to comment
Share on other sites

In your form you need to give the input a name or PHP won't be able to see it:

<FORM action="ban.php" method="post">
    <P>
    <LABEL for="firstname">Ip Address </LABEL>
<br>
              <INPUT type="text" name="address" id="address"><BR>
    <INPUT type="submit" value="Send">
    </P>
</FORM>

 

if you had looked at the file you created, you have seen that it didn't contain any IP addresses.

 

Ken

Link to comment
Share on other sites

errors:

Notice: Undefined index: address in /home/bucketho/public_html/admin/newer/more/ban.php on line 6

 

Notice: Undefined index: address in /home/bucketho/public_html/admin/newer/more/ban.php on line 6

 

Notice: Undefined variable: mes in /home/bucketho/public_html/admin/newer/more/ban.php on line 9

 

Notice: Undefined index: address in /home/bucketho/public_html/admin/newer/more/ban.php on line 6

 

Notice: Undefined variable: mes in /home/bucketho/public_html/admin/newer/more/ban.php on line 9

 

Warning: fopen(ban.txt) [function.fopen]: failed to open stream: Permission denied in /home/bucketho/public_html/admin/newer/more/ban.php on line 13

 

Notice: Undefined index: address in /home/bucketho/public_html/admin/newer/more/ban.php on line 6

 

Notice: Undefined variable: mes in /home/bucketho/public_html/admin/newer/more/ban.php on line 9

 

Warning: fopen(ban.txt) [function.fopen]: failed to open stream: Permission denied in /home/bucketho/public_html/admin/newer/more/ban.php on line 13

 

Warning: fwrite(): supplied argument is not a valid stream resource in /home/bucketho/public_html/admin/newer/more/ban.php on line 14

 

Notice: Undefined index: address in /home/bucketho/public_html/admin/newer/more/ban.php on line 6

 

Notice: Undefined variable: mes in /home/bucketho/public_html/admin/newer/more/ban.php on line 9

 

Warning: fopen(ban.txt) [function.fopen]: failed to open stream: Permission denied in /home/bucketho/public_html/admin/newer/more/ban.php on line 13

 

Warning: fwrite(): supplied argument is not a valid stream resource in /home/bucketho/public_html/admin/newer/more/ban.php on line 14

 

Warning: fclose(): supplied argument is not a valid stream resource in /home/bucketho/public_html/admin/newer/more/ban.php on line 15

 

Notice: Undefined index: address in /home/bucketho/public_html/admin/newer/more/ban.php on line 6

 

Notice: Undefined variable: mes in /home/bucketho/public_html/admin/newer/more/ban.php on line 9

 

Warning: fopen(ban.txt) [function.fopen]: failed to open stream: Permission denied in /home/bucketho/public_html/admin/newer/more/ban.php on line 13

 

Warning: fwrite(): supplied argument is not a valid stream resource in /home/bucketho/public_html/admin/newer/more/ban.php on line 14

 

Warning: fclose(): supplied argument is not a valid stream resource in /home/bucketho/public_html/admin/newer/more/ban.php on line 15

Ip has been banned!

Notice: Undefined index: address in /home/bucketho/public_html/admin/newer/more/ban.php on line 6

 

Notice: Undefined variable: mes in /home/bucketho/public_html/admin/newer/more/ban.php on line 9

 

Warning: fopen(ban.txt) [function.fopen]: failed to open stream: Permission denied in /home/bucketho/public_html/admin/newer/more/ban.php on line 13

 

Warning: fwrite(): supplied argument is not a valid stream resource in /home/bucketho/public_html/admin/newer/more/ban.php on line 14

 

Warning: fclose(): supplied argument is not a valid stream resource in /home/bucketho/public_html/admin/newer/more/ban.php on line 15

 

OMG!

Link to comment
Share on other sites

Thank you verrrrry much!!

 

I have one more problem.

 

I am making a textbox so people can select the code, how do I make it so the php code appears

 

<textarea name="group_code" class="element textarea medium pre">

<?php
$ips = array_map('trim', file('ban.txt'));
if (in_array($_SERVER['REMOTE_ADDR'],
$ips)) {exit('You have been banned!');} 
?>


</textarea>

Link to comment
Share on other sites

I'm not sure about this but I think you need to surround it by the tag like this:

 


$ips = array_map('trim', file('ban.txt'));
if (in_array($_SERVER['REMOTE_ADDR'],
$ips)) {exit('You have been banned!');} 
?>

Link to comment
Share on other sites

Guest
This topic is now 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.