Shoutbox help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nisroc
Forum Newbie
Posts: 3
Joined: Mon Feb 14, 2005 1:08 pm

Shoutbox help

Post by Nisroc »

Im very new to php and I have just go a small shoutbox to work. It is nothing big. Now that I got it working im trying to prevent it from being flooded. Im also logging ipaddresses and times to the mysql db. I was told I hate to validate the ipaddress for 120 second or so but i have no idea evactly how to do this. Anyone? ... please
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Log the time it was sent and then make sure the next submission is not less than 120 seconds from the last one. There are MySQL date functions for this, or you could do it using the unix timestamp (the same way PHP handles dates [which is already in seconds])....

What format are the times being logged in the moment?
Nisroc
Forum Newbie
Posts: 3
Joined: Mon Feb 14, 2005 1:08 pm

Post by Nisroc »

Im currently using

Code: Select all

<?php $date = Date('Y-d-m G:i:s'); echo $date ?>
for the time and date
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

why dont you just set a cookie that expires in 15 seconds? that way you dont have to build into your database at all so its super simple. just use somtin like

Code: Select all

if (isset($_COOKIE&#1111;'flood']))&#123;
     echo 'Dont flood jerkface';
&#125;else&#123;
//insert my stuff into the db
setcookie('flood', 'super flood of doom', time()+15);
&#125;
check my time()+15 i THINK thats 15 seconds but i could be super wrong
Nisroc
Forum Newbie
Posts: 3
Joined: Mon Feb 14, 2005 1:08 pm

Post by Nisroc »

ok the code worked but then i refresh page I get
Column 'ip' cannot be null
If I set ip to null it will do the same thing for link,etc etc. Im guessing the the else statement is conflicting. Am I right and if so how do i go about it?

Code: Select all

if ((isset($_POST&#1111;"MM_insert"])) && ($_POST&#1111;"MM_insert"] == "Shout") && ($_COOKIE&#1111;'flood'])) &#123;
  echo 'Dont flood jerkface';
  &#125;else&#123;
  $insertSQL = sprintf("INSERT INTO shout (ip, link, name_id, text, `time`) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST&#1111;'IP'], "text"),
                       GetSQLValueString($_POST&#1111;'Link'], "text"),
                       GetSQLValueString($_POST&#1111;'Name'], "text"),
                       GetSQLValueString($_POST&#1111;'Message'], "text"),
                       GetSQLValueString($_POST&#1111;'Time'], "text"));
					   
  setcookie('flood', 'super flood of doom', time()+15);
  mysql_select_db($database_Website, $Website);
  $Result1 = mysql_query($insertSQL, $Website) or die(mysql_error());
&#125;
[/quote]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

make collum ip in ur db NULL instead of NOT NULL. But there seam to be bigger problems than that somewere. I dunno what this %s stuff is (ya i know i should know) but why not just do.

Code: Select all

//set $ip, $link, $name_id, and $text
$ip = $HTTP_SERVER_VARS&#1111;'REMOTE_ADDR'];
$link = $_POST&#1111;'link'];
$name_id = //however you are setting your name_id;
$text = $_POST&#1111;'text'];

$query = "INSERT INTO shout (ip, link, name_id, text) VALUES ('$ip', '$link', '$name_id', '$text')";
mysql_select_db($database_Website, $Website); 
$result = mysql_query($query) or die(mysql_error());
Post Reply