sith717 Posted October 9, 2008 Share Posted October 9, 2008 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 More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 Bump Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 Your bumping 5 mins after your original post? Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 Your posting something that does not have anything to do with my post? Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 9, 2008 Share Posted October 9, 2008 What is the script supposed to do? What is it doing or not doing? Have you attempted to debug it in anyway? Ken Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 Well, the form, is supposed to post the a ip into ban.txt then the ban.php is spposed to use the ips in ban.txt thats it. Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 9, 2008 Share Posted October 9, 2008 You're writing into the file the string "IP" followed by the actual IP address, but you're only using the IP address when comparing. Ken Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 9, 2008 Share Posted October 9, 2008 The form field has no name so nothing is received in the form processing code, but the OP does not know this because he has not done any basic troubleshooting to find out what it is actually doing. Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 What does that mean? Is there anything I should take out or add in? Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 9, 2008 Share Posted October 9, 2008 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 More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 Ok, when I look at ban.php in firefox it shows errors. Does it for you? Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 9, 2008 Share Posted October 9, 2008 What are the errors? Ken Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 If you want you can upload to a host and see. I am getting different errors every time. Thank you. Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 Something is wrong. Link to comment Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Something is wrong. No shit. What are your errors? Do you have error reporting temporarily turned on? ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 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 More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 -You need to give proper permission to the ban.txt file. -$mes isn't properly defined Fix that and tell me what the errors are. Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 The current permissions are 644 Is that correct? Link to comment Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Make it 777 for now to be sure but that should work. 644 is only write for the owner. Link to comment Share on other sites More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 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 More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 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 More sharing options...
sith717 Posted October 9, 2008 Author Share Posted October 9, 2008 Instead I made it a html page. Thanks anyways. Link to comment Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 ok cool topic solved? Link to comment Share on other sites More sharing options...
sith717 Posted October 10, 2008 Author Share Posted October 10, 2008 Yes. I will be posting the code snippet. So everyone can use it. Link to comment Share on other sites More sharing options...
Lamez Posted October 10, 2008 Share Posted October 10, 2008 life is so much easier with databases! Link to comment Share on other sites More sharing options...
Recommended Posts