itsjareds Posted June 19, 2008 Share Posted June 19, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/ Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 Well in your unbanform.php, I don't see any variable named "$ip" (used in the "in_array" function). Try adding: $ip=$_POST["ip"]; Above the $alert variable and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-568728 Share on other sites More sharing options...
itsjareds Posted June 19, 2008 Author Share Posted June 19, 2008 $ip is a variable in the URL bar from the form that used this script. There's a text box that when entered creates $ip. Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-568747 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 Nothing "creates" $ip except you explicitly assigning it, unless you have register_globals on, in which case I will choke on my food. Try Stephen's idea. Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-568750 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 Oh sorry it's using GET. Do what I said before but use this code: $ip=$_GET["ip"]; EDIT: Ah okay Dark. Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-568752 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 No no, I think it's using POST. He didn't define an action, and I think the default is POST. Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-568754 Share on other sites More sharing options...
itsjareds Posted June 19, 2008 Author Share Posted June 19, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-568765 Share on other sites More sharing options...
itsjareds Posted June 19, 2008 Author Share Posted June 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-569248 Share on other sites More sharing options...
DarkWater Posted June 19, 2008 Share Posted June 19, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-569250 Share on other sites More sharing options...
itsjareds Posted June 19, 2008 Author Share Posted June 19, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/110849-banunban/#findComment-569288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.