Masterslave
02-26-2007, 06:41 PM
Hi all,
I've made a guestbook with PHP.
Some spammers put some text in the field and I get some sex ads in my guestbook that I don't want.
I want to stop this by making a reg.expr. that check for characters that are not allowed.
These are "<" ">" "[" "]".
I've chose these because the spammers uses HTML and BB-code tags.
Can anyone tell me how to make this.
My reg.expr skills aren't that good....
Can I do this with preg_match of ereg ?
PHP part guestbook.php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "GET")
{
$_SESSION["guestbook"] = true;
}
MySQL:
if (isset($_SESSION["guestbook"]))
{
if(isset($_POST['submit']))
{
if (trim(empty($_POST['name'])) || trim(empty($_POST['content'])))
{
$error = "<br /><strong>Je dient je naam en bericht op te geven om een bericht te plaatsen.</strong>";
}
else
{
$commentInsert = " INSERT INTO
$guestbooktable
(
name,
email,
website,
content,
ip,
host
)
VALUES
(
'" . mysql_real_escape_string($_POST['name']) . "',
'" . mysql_real_escape_string($_POST['email']) . "',
'" . mysql_real_escape_string($_POST['website']) . "',
'" . mysql_real_escape_string($_POST['content']) . "',
'" . mysql_real_escape_string($_POST['ip']) . "',
'" . mysql_real_escape_string($_POST['host']) . "'
)";
$result = mysql_query($commentInsert) or die (mysql_error());
header("Location: guestbook.php");
}
}
}
else
{
die();
}
Thanks for your help.
I've made a guestbook with PHP.
Some spammers put some text in the field and I get some sex ads in my guestbook that I don't want.
I want to stop this by making a reg.expr. that check for characters that are not allowed.
These are "<" ">" "[" "]".
I've chose these because the spammers uses HTML and BB-code tags.
Can anyone tell me how to make this.
My reg.expr skills aren't that good....
Can I do this with preg_match of ereg ?
PHP part guestbook.php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "GET")
{
$_SESSION["guestbook"] = true;
}
MySQL:
if (isset($_SESSION["guestbook"]))
{
if(isset($_POST['submit']))
{
if (trim(empty($_POST['name'])) || trim(empty($_POST['content'])))
{
$error = "<br /><strong>Je dient je naam en bericht op te geven om een bericht te plaatsen.</strong>";
}
else
{
$commentInsert = " INSERT INTO
$guestbooktable
(
name,
email,
website,
content,
ip,
host
)
VALUES
(
'" . mysql_real_escape_string($_POST['name']) . "',
'" . mysql_real_escape_string($_POST['email']) . "',
'" . mysql_real_escape_string($_POST['website']) . "',
'" . mysql_real_escape_string($_POST['content']) . "',
'" . mysql_real_escape_string($_POST['ip']) . "',
'" . mysql_real_escape_string($_POST['host']) . "'
)";
$result = mysql_query($commentInsert) or die (mysql_error());
header("Location: guestbook.php");
}
}
}
else
{
die();
}
Thanks for your help.