Jump to content

Functions and submit for timed kicking


cobusbo

Recommended Posts

Hi guys im having trouble implementing functions into some buttons. I got a kicking script from the internet that looks as follow

 

 
<?php
// Published at: www.TakeTwoApps.com




$ipLog='ip-log.txt'; // Your logfiles name here
$timeout='0.01'; // How many hours to block IP
$goHere='allowed-page.html'; // Allowed pages name here




$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) $vis_ip = getenv(REMOTE_ADDR);
else $vis_ip = $_SERVER['REMOTE_ADDR'];




function recordData($vis_ip,$ipLog,$goHere)
{ 
    $log=fopen("$ipLog", "a+"); 
    fputs ($log,$vis_ip."][".time()."\n"); 
    fclose($log); 


    // The below header function was causing errors in apache 
    //so I changed it to echo the script tag. 
    //Header ("Location: $goHere"); exit(0);  
    echo "<script>location.replace('$goHere')</script>"; exit(0);
} 
function checkLog($vis_ip,$ipLog,$timeout) 
{
    global $valid; $ip=$vis_ip;
    $data=file("$ipLog"); $now=time();


    foreach ($data as $record) 
    {
        $subdata=explode("][",$record);
        if ($now < ($subdata[1]+3600*$timeout) && $ip == $subdata[0]) 
        {
            $valid=0; echo "You have been banned from accessing this page. Try again in $timeout hours.";
            break;
        }
    }
} 
checkLog($vis_ip,$ipLog,$timeout);
if ($valid!="0") recordData($vis_ip,$ipLog,$goHere); 


?>


but what im trying to do is to make 3 different times for kicking. lets say a kick for 1h, 24h and one for 7 days. So it will mean I will have to make 3 of the above scripts. But now my problem is that I want to implement the above functions into the following buttons

 

<input name="1" type="submit" id="1" value="Kick <? echo $myrow["StringyChat_ip"];?> for 1 hour ">
<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 ">

 in the following script

 

<?
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</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="1" type="submit" id="1" value="Kick <? echo $myrow["StringyChat_ip"];?> for 1 hour ">
<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>
  <?
  }   
?>


  

but im not sure how to connect the function to kick someone to the button 1, 1d and 7d... can anybody assist me with this please.

 

And lastly my kicking script at the top. got the function

    echo "<script>location.replace('$goHere')</script>"; exit(0);

to redirect me to another page. but how can I change the line to rather include a specific page on the current page when the ban has been lifted... and how do I check on the page if the ban has been lifted or not?

Edited by cobusbo
Link to comment
Share on other sites

You're trying to write a script (using out dated code1) that will ban users based on their IP? 

yes, since its the only example I could find on the internet, to automatic unban user after a specified time...

Link to comment
Share on other sites

Guest
This topic is now 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.