Jump to content


Photo

ip ban script causing 500 error


  • Please log in to reply
3 replies to this topic

#1 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 14 August 2006 - 06:36 AM

Please help, my ip banning script is causing a 500 error, here is the script:
<? include "site_top.php"; ?>
<?php 
require("config.php"); 
switch ($_GET[id]) {
default:
if(!isset($_POST[ban])){ // If the submit button hasnt been pressed 
echo "<form method='post'>
<b>IP Address:</b><br>
<input type='text' name='ip' maxlength='50'>
<br>
<b>Reason:</b> 
<br> 
<textarea name='reason' cols='30' rows='5'></textarea>
<br>
<input type='submit' name='ban' value='Ban IP'>
</form>";
}
if($_POST[ban]){ // If the submit button is pressed 
$ip = $_POST['ip']; //Get the name field 
$reason = $_POST['reason'];//Get the message filed 
if($ip == NULL || $reason == NULL){ // If either fields are left blank.. 
echo "A field was left blank, please go back and fix this."; //Echo a field was left blank. 
}else{ // If neither fields are blank... 
$postcmt = mysql_query("INSERT INTO `banned` (ip,reason,by) VALUES ('$ip','$reason','$logged[username]')"); //Insert the shout 
echo "The IP has been banned."; // Echo shout was posted 
} 
} 
$listbans = mysql_num_rows(mysql_query("SELECT * FROM banned ORDER BY id DESC"));
if ($listbans < 1) {
echo "<br />No bans have been made";
}
else {
$bans = mysql_fetch_array(mysql_query("SELECT * FROM banned ORDER BY id DESC"));
while ($b = $bans) {
echo "<br />IP: $b[ip]<br />Reason: $b[reason]<br />By: $b[by]-----<a href=\"ipban.php?id=delete&ip=$b[ip]\">DELETE</a><br />";
}
}
break;
case 'delete':
if (!$_GET[ans] && $_GET[ip]) {
echo "Are you sure you want to delete this ban? <a href=\"ipban.php?id=delete&ans=yes\">Yes</a> Or <a href=\"ipban.php?id=delete&ans=no\">No</a>?";
}
elseif ($_GET[ans] == no && $_GET[ip]) {
echo "You desided to keep the ban";
}
elseif ($_GET[ans] == yes && $_GET[ip]) {
echo "Deleting ban...........";
$delete = mysql_query("DELETE FROM banned WHERE ip = '$_GET[ip]'");
echo "Ban deleted!!";
}
else {
echo "You have reached a invalid page";
}
break;
}
?>
<? include "site_bot.php"; ?>


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 14 August 2006 - 06:57 AM

The best way(that I know of) to set up a switch statment is like this.

<?php
include("whatever.php");

function showpage($page) {
     switch ($page) {
         case "case 1":
         //some code here
         break;
         case "case 2":
         break;
     default:
     //your default code goes here
     }
}
showpage($_GET['page']);//you need this to execute your code
?>

Now you can link to this like this whatever.php?page=case1

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 14 August 2006 - 07:24 AM

I don't care the best way to do a switch statment, can you help me or not

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 14 August 2006 - 08:01 AM

I don't care the best way to do a switch statment, can you help me or not


With an attitude like that I most certainly will not and I doubt that anyone else will ether.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users