Jump to content

Timed ban Script errors please help


cobusbo

Recommended Posts

Hi Ive made a database with the option to kick someone for a certain amount of time but seems like I'm doing something wrong somewhere can anybody please assist

 

My full script is 

 

(Admin panel)

<?
include "./emoticon_replace1.php";


  if ($_POST["DeletePost"]) {
    $id = $_POST["id"];
    $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
    mysql_query($query);
    echo "ID removed from system: ".$id;
  }
  if ($_POST["BanIP"]) {
    $IP_To_Add = $_POST["ip"];
    if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))
    {
      $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
      $result = mysql_query($sql);
    } else {
      echo "Error: Not a valid IP: ".$IP_To_Add;
    }
  }
  if ($_POST["purge"]) {
    $query = "TRUNCATE TABLE ".$dbTable; 
    mysql_query($query);
    echo "StringyChat purged";
  }
  if(!$_POST["update"] || !$_POST["StringyChat_name"] || !$_POST["StringyChat_message"]) {
  } else {
    $id = $_POST["id"];
    $name = $_POST["StringyChat_name"];
    $message = $_POST["StringyChat_message"];


    include("emoticon_replace.php");


    $query = "UPDATE ".$dbTable." SET StringyChat_name='$name', StringyChat_message='$message' WHERE id='".$id."'";
    $result = mysql_query($query, $db) or die("Invalid query: " . mysql_error());
  }
  if ($_POST["EditPost"]) {
    $id = $_POST["id"];
    $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'", $db); 
    $myrow = mysql_fetch_array($result);
?>
    <form name="StringyChat_form" method="POST" action="?mode=postman">
      Name:<br>
      <input name="StringyChat_name" class="StringyChatFrm" type="text" size="20" maxlength="<? echo $name_size; ?>" value="<? echo $myrow["StringyChat_name"]?>">
      <br>
      Message:<br>
      <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="4"><? echo $myrow["StringyChat_message"]?></textarea>
      <br>
      <input type="hidden" name="id" value="<? echo $id ?>">
      <input name="update" class="StringyChatFrm" type="submit" value="Update">
    </form>


<?
  }
?>


  <a href="<? echo $_SERVER['REQUEST_URI']; ?>&m=purge">Purge StringyChat</a><br>
    <br>


  <?
  // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
  $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC",$db);


  while ($myrow = mysql_fetch_array($result)) {
    $msg = $myrow["StringyChat_message"];


    $msg = strip_tags($msg);
    $msg = eregi_replace("im#([a-z]{3})", "<img src=\"/stringychat/images/\\1.gif\" alt=\"emoticon\">",$msg);


printf("<div class=\"StringyChatItem\"><h4>%s<br>\n", $myrow["StringyChat_name"]);
printf("%s<p>\n",$myrow["StringyChat_ip"],"%s</p>\n");
    printf("%s</h4>\n", date("H:i - d/m/y", $myrow["StringyChat_time"]));
    printf("%s</div>\n", $msg);




if ($_POST["1h"]) {
    $mxitid1= $_POST["1h"];
    if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))
    {
      $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)";
      $result1 = mysql_query($sq1l);
    } else {
      echo "Error: Cannot Kick: ".$IP_To_Add;
    }
  }
function checkban($mxitid) 
    { 
        // querys database 
        $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db); 
        $get = mysql_num_rows($q); 
        // if found 
        if ($get == "1") 
            {  
                // deny user access 
                $r=mysql_fetch_array($q); 
                die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster at ."); 
            } 
    }








?>
    <form name="form<? echo $myrow["id"];?>" method="post" action="?mode=postman">
      <input name="id" type="hidden" value="<? echo $myrow["id"];?>">
      <input name="ip" type="hidden" value="<? echo $myrow["StringyChat_ip"];?>">
      <input name="EditPost" type="submit" id="EditPost" value="Edit">
      <input name="DeletePost" type="submit" id="DeletePost" value="Delete">
      <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>">
<input name="1h" type="submit" id="1" value="Kick <? echo $myrow["mxit_id"];?>">
<input name="1d" type="submit" id="1d" value="Kick <? echo $myrow["StringyChat_ip"];?> for 24 hours ">
<input name="7d" type="submit" id="7d" value="Kick <? echo $myrow["StringyChat_ip"];?> for 7 days ">
    </form>
  <?
  }   
?>

The part I added to the above script which is giving me pain is 

 

if ($_POST["1h"]) {
    $mxitid1= $_POST["1h"];
    if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))
    {
      $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)";
      $result1 = mysql_query($sq1l);
    } else {
      echo "Error: Cannot Kick: ".$IP_To_Add;
    }
  }
function checkban($mxitid) 
    { 
        // querys database 
        $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db); 
        $get = mysql_num_rows($q); 
        // if found 
        if ($get == "1") 
            {  
                // deny user access 
                $r=mysql_fetch_array($q); 
                die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster at ."); 
            } 
    }

What I'm trying to do is to ban the person for 1 day. And by banning the person I want them to be blocked from my Index page from submitting a form (sending a message) which is stored as tik.php on my index page

 

 

index.php

<?php
require_once('common.php');


include "ip-ban-time-limit.php";
checkban($_SERVER['HTTP_X_MXIT_USERID_R']);






checkUser();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Galaxy Universe Chat</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body><br>
    <div id="main">
      <div class="caption">Galaxy Universe Chat</div>
      <div id="icon"> </div>
      <div id="result">
Hello <?php echo $_SESSION['userName']; ?> ! <br/>
<div style="color:red"><b><p>Please keep it clean and in English or you will be banned!</p></b></div>
<br>
<?PHP


include "./stringychat.inc.php";
require_once ( 'tik.php' );


?>


<br>




<p><a href="index1.php">Refresh</a> | <a href="logout.php">Log Out</a></p>
 </div> 
 <div id="source">Galaxy Wars chat @ cobusbo</div>
    </div>
</body>   

Seems like I've been doing something wrong with my queries...

 

Link to comment
Share on other sites

And you think something's wrong because...

 

What's happening and what's supposed to be happening?

 

 

 

trying to load my index.php file i get the error

 

 

 

Fatal error: Call to undefined function checkban() in /home/u506124311/public_html/ag/index1.php on line 4

trying to load my admin page

 

 

 

Fatal error: Cannot redeclare checkban() (previously declared in /home/u506124311/public_html/ag/admin_post_management.php:85) in/home/u506124311/public_html/ag/admin_post_management.php on line 85

and when i press kick button it says

 

 

 

Error: Cannot Kick:

So my problem is within my queries and form but not sure what I should do...

Link to comment
Share on other sites

The errors are self explanatory.

 

 

trying to load my index.php file i get the error

Fatal error: Call to undefined function checkban() in /home/u506124311/public_html/ag/index1.php on line 4

 

You are trying to call your checkban() function which you have not been defined!  You have only defined this function your admin script. PHP will not be aware of that. So you need to make that function accessible from index1.php. I would suggest moving any common used functions into a separate file and then include that file when you are going to use a common function.

 

 

try to load the admin page

Fatal error: Cannot redeclare checkban() (previously declared in /home/u506124311/public_html/ag/admin_post_management.php:85) in/home/u506124311/public_html/ag/admin_post_management.php on line 85

You have defined this function more than once. Function names must be unique.

 

EDIT: You are getting that error because you have this code within your while loop

if ($_POST["1h"]) {
    $mxitid1= $_POST["1h"];
    if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))
    {
      $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)";
      $result1 = mysql_query($sq1l);
    } else {
      echo "Error: Cannot Kick: ".$IP_To_Add;
    }
  }
function checkban($mxitid) 
    { 
        // querys database 
        $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db); 
        $get = mysql_num_rows($q); 
        // if found 
        if ($get == "1") 
            {  
                // deny user access 
                $r=mysql_fetch_array($q); 
                die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster at ."); 
            } 
    }

Move that code so it is not within thewhile loop. For example move it so it is before this line in your admin script

while ($myrow = mysql_fetch_array($result)) {

 

and when i press kick button it says

Error: Cannot Kick:

You are getting that error because the regex pattern used on the line below does not match the value in $IP_To_Add

if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))

NOTE: You should not be using ereg*() functions they are deprecated and no longer supported. You need to convert any use of ereg*() functions to use the PCRE functions. For example if your are using eregi() you need to use preg_match() applying the i pattern modifier to the regex pattern.

Edited by Ch0cu3r
Link to comment
Share on other sites

The errors are self explanatory.

 

 

You are trying to call your checkban() function which you have not been defined!  You have only defined this function your admin script. PHP will not be aware of that. So you need to make that function accessible from index1.php. I would suggest moving any common used functions into a separate file and then include that file when you are going to use a common function.

 

You have defined this function more than once. Function names must be unique.

 

EDIT: You are getting that error because you have this code within your while loop

if ($_POST["1h"]) {
    $mxitid1= $_POST["1h"];
    if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))
    {
      $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)";
      $result1 = mysql_query($sq1l);
    } else {
      echo "Error: Cannot Kick: ".$IP_To_Add;
    }
  }
function checkban($mxitid) 
    { 
        // querys database 
        $q = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db); 
        $get = mysql_num_rows($q); 
        // if found 
        if ($get == "1") 
            {  
                // deny user access 
                $r=mysql_fetch_array($q); 
                die("You have been banned from this website until $r[legnth]. If you feel this is in error, please contact the webmaster at ."); 
            } 
    }

Move that code so it is not within thewhile loop. For example move it so it is before this line in your admin script

while ($myrow = mysql_fetch_array($result)) {

You are getting that error because the regex pattern used on the line below does not match the value in $IP_To_Add

if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))

NOTE: You should not be using ereg*() functions they are deprecated and no longer supported. You need to convert any use of ereg*() functions to use the PCRE functions. For example if your are using eregi() you need to use preg_match() applying the i pattern modifier to the regex pattern.

Ok after implementing the above I'm receiving the following error on my admin page

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/func.ban.php on line 9

 and my Admin page looks like this

 

<?
include "./emoticon_replace1.php";


  if ($_POST["DeletePost"]) {
    $id = $_POST["id"];
    $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; 
    mysql_query($query);
    echo "ID removed from system: ".$id;
  }
  if ($_POST["BanIP"]) {
    $IP_To_Add = $_POST["ip"];
    if(eregi("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $IP_To_Add))
    {
      $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")";
      $result = mysql_query($sql);
    } else {
      echo "Error: Not a valid IP: ".$IP_To_Add;
    }
  }
  if ($_POST["purge"]) {
    $query = "TRUNCATE TABLE ".$dbTable; 
    mysql_query($query);
    echo "StringyChat purged";
  }
  if(!$_POST["update"] || !$_POST["StringyChat_name"] || !$_POST["StringyChat_message"]) {
  } else {
    $id = $_POST["id"];
    $name = $_POST["StringyChat_name"];
    $message = $_POST["StringyChat_message"];


    include("emoticon_replace.php");


    $query = "UPDATE ".$dbTable." SET StringyChat_name='$name', StringyChat_message='$message' WHERE id='".$id."'";
    $result = mysql_query($query, $db) or die("Invalid query: " . mysql_error());
  }
  if ($_POST["EditPost"]) {
    $id = $_POST["id"];
    $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'", $db); 
    $myrow = mysql_fetch_array($result);
?>
    <form name="StringyChat_form" method="POST" action="?mode=postman">
      Name:<br>
      <input name="StringyChat_name" class="StringyChatFrm" type="text" size="20" maxlength="<? echo $name_size; ?>" value="<? echo $myrow["StringyChat_name"]?>">
      <br>
      Message:<br>
      <textarea name="StringyChat_message" class="StringyChatFrm" cols="20" rows="4"><? echo $myrow["StringyChat_message"]?></textarea>
      <br>
      <input type="hidden" name="id" value="<? echo $id ?>">
      <input name="update" class="StringyChatFrm" type="submit" value="Update">
    </form>


<?
  }
?>


  <a href="<? echo $_SERVER['REQUEST_URI']; ?>&m=purge">Purge StringyChat</a><br>
    <br>


  <?
  // Load up the last few posts.  The number to load is defined by the "ShowPostNum" variable.
  $result = mysql_query("SELECT * FROM ".$dbTable." ORDER BY StringyChat_time DESC",$db);


  while ($myrow = mysql_fetch_array($result)) {
    $msg = $myrow["StringyChat_message"];


    $msg = strip_tags($msg);
    $msg = eregi_replace("im#([a-z]{3})", "<img src=\"/stringychat/images/\\1.gif\" alt=\"emoticon\">",$msg);


printf("<div class=\"StringyChatItem\"><h4>%s<br>\n", $myrow["StringyChat_name"]);
printf("%s<p>\n",$myrow["StringyChat_ip"],"%s</p>\n");
    printf("%s</h4>\n", date("H:i - d/m/y", $myrow["StringyChat_time"]));
    printf("%s</div>\n", $msg);












?>
    <form name="form<? echo $myrow["id"];?>" method="post" action="?mode=postman">
      <input name="id" type="hidden" value="<? echo $myrow["id"];?>">
      <input name="ip" type="hidden" value="<? echo $myrow["StringyChat_ip"];?>">
      <input name="EditPost" type="submit" id="EditPost" value="Edit">
      <input name="DeletePost" type="submit" id="DeletePost" value="Delete">
      <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>">
<input name="1h" type="submit" id="1" value="Kick <? echo $myrow["mxit_id"];?>">
<input name="1d" type="submit" id="1d" value="Kick <? echo $myrow["StringyChat_ip"];?> for 24 hours ">
<input name="7d" type="submit" id="7d" value="Kick <? echo $myrow["StringyChat_ip"];?> for 7 days ">
    </form>
  <?
  }   




if ($_POST["1h"]) {
    $mxitid1= $_POST["1h"];
    if(!ip)
    { echo "you must put in an MXIT ID";
}


      $sql1 = "UPDATE ".$dbTable." SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)";
      $result1 = mysql_query($sq1l);
    } 












?>


  

and on my index page I receive the following error

 

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/u506124311/public_html/ag/func.php on line 9

 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/func.php on line 10

 

And my Index file looks like the following

 

<?php
require_once('common.php');
include "func.php";
checkban($_SERVER['HTTP_X_MXIT_USERID_R']);






checkUser();
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Galaxy Universe Chat</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body><br>
    <div id="main">
      <div class="caption">Galaxy Universe Chat</div>
      <div id="icon"> </div>
      <div id="result">
<span style="color:lime">Hello <?php echo $_SESSION['userName']; ?> ! </span><br/>
<div style="color:red"><b>Please keep it clean and in English or you will be banned!</b></div>
<br>
<?PHP
include "./page.php";
include "./stringychat.inc.php";


?>


<br>




<p><a href="index1.php">Refresh</a> | <a href="logout.php">Log Out</a></p>
 </div> 
 <div id="source">Galaxy Wars chat @ cobusbo</div>
    </div>
</body>   

and lastly my func.php looks like 

 

<?php


$mxitid = $_SERVER["HTTP_X_MXIT_USERID_R"];
    require("admin_code_header.php");


function checkban($mxitid) 
    { 
        // querys database 
        $q2 = mysql_query("SELECT 1 FROM ".$dbTable." WHERE unban_time > NOW() AND mxit_id = '$mxitid'",$db); 
        $get1 = mysql_num_rows($q2); 
        // if found 
        if ($get1 == "1") 
            {  
                // deny user access 
                $r=mysql_fetch_array($q2); 
                die("You have been banned from this website until . If you feel this is in error, please contact the webmaster at ."); 
            } 
    }




?>
Any help?
Link to comment
Share on other sites

Your mysql query is failing, thereby returning false instead of a resource ID. This is likely because of a scope issue.  When you have a function, any variables inside of the function must be created in the function itself, OR be passed in the arguments (I purposely steered clear of explaining globals here).  Going further with the explanation, I can tell you that $dbTable, and $db are unknown variables in your function checkban().  You will either have to hard code them, or pass them in the arguments.

 

Since you hard coded the column names, it wouldn't be to hard to hard code the table name.  Then either create a db connection inside of the function (useless, unless that is the only db call), or pass it in.

 

My suggestion would be:

 

function checkban($mxitid,$db) {
Link to comment
Share on other sites

 

Your mysql query is failing, thereby returning false instead of a resource ID. This is likely because of a scope issue.  When you have a function, any variables inside of the function must be created in the function itself, OR be passed in the arguments (I purposely steered clear of explaining globals here).  Going further with the explanation, I can tell you that $dbTable, and $db are unknown variables in your function checkban().  You will either have to hard code them, or pass them in the arguments.

 

Since you hard coded the column names, it wouldn't be to hard to hard code the table name.  Then either create a db connection inside of the function (useless, unless that is the only db call), or pass it in.

 

My suggestion would be:

function checkban($mxitid,$db) {

Ok so I changed my func.php to

 

<?php


$mxitid = $_SERVER["HTTP_X_MXIT_USERID_R"];
    require("admin_code_header.php");


function checkban($mxitid) 
    { 
        // querys database 
        $q2 = mysql_query("SELECT 1 FROM StringyChat WHERE unban_time > NOW() AND mxit_id = $mxitid"); 
        $get1 = mysql_num_rows($q2); 
        // if found 
        if ($get1 == "1") 
            {  
                // deny user access 
                $r=mysql_fetch_array($q2); 
                die("You have been banned from this website until . If you feel this is in error, please contact the webmaster at ."); 
            } 
    }




?>

 

 

 

But now I'm still receiving this error on my Admin page

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/func.ban.php on line 9

 

and the same error on my index page

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u506124311/public_html/ag/func.php on line 10

 

 

 

And it seems like my option to insert the ban time to my Database don't work as well...

if ($_POST["1h"]) {
    $mxitid1= $_POST["1h"];
    if(!$mxitid1)
    { echo "you must put in an MXIT ID";
}


      $sql1 = "INSERT StringyChat SET unban_time = DATE_ADD(NOW(), INTERVAL 1 DAY) WHERE mxit_id = $mxitid1)";
      $result1 = mysql_query($sq1l);
    } 

 from my admin page...

 

My unban_time field in my database has been set as INT (10) and no default value...

Edited by cobusbo
Link to comment
Share on other sites

At this point, you need to add some de-bugging to your queries to make sure they are processing correctly.

 

like:

$q2 = mysql_query(...) or trigger_error(mysql_error()); 

You should really port over to mysqli at the least.  mysql is very old.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.