Jump to content

Ban/Unban


itsjareds

Recommended Posts

I'm trying to write a script to ban/unban people off of my site. Both parts work fine except, when I unban, my script doesn't delete all of what was in an array.

 

I don't know if I'm explaining this very well, so I'll just show my code.

 

banned IPs (ips.php)

123.4.567.890

 

form for unbanning (unban.html)

<?php include("banned.php") ?>
<html>
<head>

<title>Unban</title>
</head>
<body>

<center>
Find a list of people who went on the board <a href="log.html">here</a>.
<br>
<br>
<br>
<form action="unbanform.php">
IP address: <input type="text" name="ip"><br><br>
<input type="submit" value="Unban!" style="width: 220px; height: 45px">
</form>
</center>

</body>
</html>

 

unban form action (unbanform.php)

<?php include("banned.php") ?>
<?php

$alert = "ips.php";
$ip_string = file_get_contents("ips.php");
$banned = explode("\n", $ip_string);

$handle = @fopen($alert,'w');
if($handle)
{
  if (in_array($ip, $banned))
  {
    $bancount = count($banned);
    $bancount++;
    for ($a=0; $a < $bancount; $a++)
    {
      if ($banned[a] == $ip)
      {
        unset($banned[a]);
      }
    }
  $bancount = count($banned);
  for ($c=0; $c < $bancount; $c++)
    {
    $ip_string = $ip_string + $banned[c];
    }
  fwrite($handle,"\r\n".$ip_string);
  fclose($handle);
  }
  
  else 
  { 
    die("<center><H3><font color=\"red\">ERROR: ". $ip ." is not banned.</H3></center>");
  }  
}

echo "<center><H3>User with the IP <font color=\"red\">" . $ip . "</font> has been unbanned.<br /></H3></center>";

?>

 

Hope there's someone out there who can help. Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/110849-banunban/
Share on other sites

Theres a form that uses unbanform.php (unban.php)

<?php include("login.php") ?>
<html>
<head>

<title>Multiboard Unban</title>
</head>
<body>

<center>
Find a list of people who went on the board <a href="log.html">here</a>.
<br>
<br>
<br>
<form action="unbanform.php">
IP address: <input type="text" name="ip"><br><br>
<input type="submit" value="Unban!" style="width: 220px; height: 45px">
</form>
</center>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/110849-banunban/#findComment-568765
Share on other sites

Besides, getting $ip isn't the problem. It seems to be doing it on its own. What I need help with is erasing one entry from an array and then saving the array back to the file.

 

Since i read the contents of the array, i have to save it again, but if theres nothing in the array, then it just returns "Array" into ips.php

Link to comment
https://forums.phpfreaks.com/topic/110849-banunban/#findComment-569248
Share on other sites

If you echo an array, it'll always produce "Array ()".  You need to use print_r() on an array.  Anyway, it SHOULDN'T be getting $ip on its own.  Check in your php.ini to see if you have register_globals on, which you ABSOLUTELY shouldn't, because it's turned off by default.

Link to comment
https://forums.phpfreaks.com/topic/110849-banunban/#findComment-569250
Share on other sites

I wouldnt know about php.ini because i don't own the server  :-[ i'm on a subdomain.

 

With the array, I read the file and exploded it. The format of the file (ips.php) before it is exploded is:

1st.i.p
2nd.i.p

 

with line breaks inbetween.

 

How could i "unexplode" the array back to that format, without the array entry i have unset?

 

Link to comment
https://forums.phpfreaks.com/topic/110849-banunban/#findComment-569288
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.