Jump to content

[SOLVED] Please help me out here...


clown[NOR]

Recommended Posts

I'm making a guestbook but something is very wrong here... Adding the message to the database works perfectly, but the issue comes when it's added. The user can just hit F5 and the message get's added again.. And you can keep on doing that forever spamming the guestbook really bad.. So I wonder if anyone could tell me how to prevent that from happening. Here's the code:

 

<?php

if (isset($_REQUEST['Submit'])) {

	$name = $_REQUEST['name'];
	$email = $_REQUEST['email'];
	$website = $_REQUEST['website'];
	$message = $_REQUEST['message'];
	$ip = $_SERVER['REMOTE_ADDR'];
	$added = date("Y-m-d H:i:s");

	if (empty($name)) { $name = "Anonymous"; }

	$name = strip_tags($name);
	$email = strip_tags($email);
	$website = strip_tags($website);
	$message = str_replace("\n", "<br>", strip_tags($message));

	c2db();

	$name = mysql_real_escape_string($name);
	$email = mysql_real_escape_string($email);
	$website = mysql_real_escape_string($website);
	$message = mysql_real_escape_string($message);
	$ip = mysql_real_escape_string($ip);
	$added = mysql_real_escape_string($added);

	$query = "INSERT INTO `guestbook` VALUES ('', '$name', '$email', '$website', '$message', '$ip', '$added')";
	$result = mysql_query($query);
	if (!$result) { die(mysql_error()); }
	unset($_REQUEST['Submit']);

}

?>

Thanks in Advance
- Clown

Link to comment
Share on other sites

using header('location: www.xxx.com'); after the insert query will help also storing their ip address and teh timestamp will allow you to check the last time they posted (and you can deny them if the time is less than a specified period).

Link to comment
Share on other sites

Try this!

 

<?php
if (isset($_REQUEST['Submit'])) {//Page was submitted
   if (!$_REQUEST['Submit']) { //value of content is empty
    header("Location: http:// ");
   } else { //Submit has value

	$name = $_REQUEST['name'];
	$email = $_REQUEST['email'];
	$website = $_REQUEST['website'];
	$message = $_REQUEST['message'];
	$ip = $_SERVER['REMOTE_ADDR'];
	$added = date("Y-m-d H:i:s");

	if (empty($name)) { $name = "Anonymous"; }

	$name = strip_tags($name);
	$email = strip_tags($email);
	$website = strip_tags($website);
	$message = str_replace("\n", "<br>", strip_tags($message));

	c2db();

	$name = mysql_real_escape_string($name);
	$email = mysql_real_escape_string($email);
	$website = mysql_real_escape_string($website);
	$message = mysql_real_escape_string($message);
	$ip = mysql_real_escape_string($ip);
	$added = mysql_real_escape_string($added);

	$query = "INSERT INTO `guestbook` VALUES ('', '$name', '$email', '$website', '$message', '$ip', '$added')";
	$result = mysql_query($query);
	if (!$result) { die(mysql_error()); }
	unset($_REQUEST['Submit']);
 }

}
?>

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.