Hi all!
I'm tierd to block ip's of spam bots in my guest book
source code
I was thinking to add at least a small check box so that is not easy to sign, can anyone help or have better idea?
here's the sign.php first part ( can't fit everything in this post)
<?php
/*
Xeobook v0.935 [2002-11-28]
http://xeoman.com
(c) 2002 Xeoman
*/
if ($trashnow == 'false') {
header("Location: index.php");
}
$gb_user_ip = $REMOTE_ADDR;
$gb_user_host = @getHostByAddr($REMOTE_ADDR);
$gb_user_agent = $HTTP_USER_AGENT;
$gb_user_lang = substr($HTTP_ACCEPT_LANGUAGE, 0, 2);
if (!$gb_user_lang) {$gb_user_lang = 'en';}
include('config.php');
$conf_magicquotes = get_magic_quotes_gpc();
if (!$gb_lang_installed) {$gb_langpath = 'lang/en.php';}
if (eregi($gb_user_lang, $gb_lang_installed)) {
@include('lang/' . $gb_user_lang . '.php');
} else {
@include($gb_langpath);
}
session_start();
if (!$PHPSESSID) {
session_register('gb_parole_try');
} elseif (!$gb_parole_try) {
session_register('gb_parole_try');
}
if (($gb_flood_ip == $gb_user_ip) && (abs(time() - $gb_flood_last) < ($gb_flood_min * 60))) {
$gb_flooding = 'true';
} else {
$gb_flooding = NULL;
}
echo $testme;
function format_entries($reval) {
if ($reval) {
global $gb_tags, $gb_entrymaxlength;
$reval = trim($reval);
$reval = strip_tags($reval, $gb_tags);
if (strlen($reval) > $gb_entrymaxlength) {
$reval = substr($reval, 0, $gb_entrymaxlength);
$reval .= $m_maxchars;
}
$reval = str_replace(" ", " ", $reval);
$reval = str_replace("\n ", "\n", $reval);
}
return $reval;
}
function format_wordlength($text) {
global $gb_entrywordlength;
$text_array = split (Chr(32), $text);
for ($i=0; $i < sizeof($text_array); $i++) {
if (strlen($text_array[$i]) > $gb_entrywordlength) {
$text_array[$i] = substr($text_array[$i], 0, $gb_entrywordlength);
}
}
$text = implode(Chr(32), $text_array);
return $text;
}
function format_entrylength($entryval, $entrylength) {
if (!$entrylength) {
$entrylength == 40;
}
if (strlen($entryval) < $entrylength) {
$entryval = substr($entryval, 0, $entrylength);
}
return $entryval;
}
if (strlen(format_entries($gb_entry_text)) < $gb_entryminlength) {
$gb_entry_text = NULL;
}
#========================================
# This will happen if you click SIGN GUESTBOOK
#========================================
if (($todo == 'add') && ($gb_flooding)) {
$msg = "<p class=\"messagetext\">$m_signedalready<br></p><p><a class=\"buttonview\" href=\"index.php\">Back</a><br></p>";
} elseif ($todo == 'add' && ($gb_entry_text)) {
$gb_entry_date = date("Y-m-d H:i:s");
if (!eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\\.)+[a-z]{2,4}$", $gb_email)) {
$gb_email = NULL;
}
if ($gb_homepage == 'http://') {
$gb_homepage = NULL;
}
if (!eregi("^http://[_a-z0-9-]+\\.[_a-z0-9-]+", $gb_homepage)) {
$gb_homepage = NULL;
}
if (!$gb_fullname) {
$gb_fullname = $gb_noname;
}
$gb_fullname = format_entries($gb_fullname);
$gb_fullname = format_entrylength($gb_fullname, 20);
$gb_sex = format_entries($gb_sex);
$gb_sex = format_entrylength($gb_sex, 6);
$gb_location = format_entries($gb_location);
$gb_location = format_entrylength($gb_location, 20);
$gb_url = format_entries($gb_url);
$gb_url = format_entrylength($gb_url, 100);
$gb_email = format_entries($gb_email);
$gb_email = format_entrylength($gb_email, 50);
$gb_entry_text = format_entries($gb_entry_text);
$gb_entry_text = format_wordlength($gb_entry_text);
$gb_comment_text = format_entries($gb_comment_text);
$gb_comment_text = format_wordlength($gb_comment_text);
$gb_mess_brand = format_entries($gb_mess_brand);
$gb_mess_brand = format_entrylength($gb_mess_brand, 20);
$gb_mess_nick = format_entries($gb_mess_nick);
$gb_mess_nick = format_entrylength($gb_mess_nick, 15);
$gb_user_pass = md5(session_id() . rand(1, 999) . time());
$link = @mysql_connect ("$sql_host", "$sql_id", "$sql_pass")
or die ($sql_error);
@mysql_select_db("$sql_db");
if ($conf_magicquotes == 0) {
foreach($GLOBALS as $k=>$v) {
if (substr_count($k, "gb_") > 0) {
$GLOBALS[$k] = addslashes($v);
}
}
}
$insertstring = "INSERT INTO $sql_table(gb_fullname, gb_sex, gb_email, gb_homepage, gb_location, gb_entry_text, gb_entry_date, gb_mess_brand, gb_mess_nick, gb_user_ip, gb_user_host, gb_user_agent, gb_user_lang, gb_user_pass) VALUES " .
"('$gb_fullname', '$gb_sex', '$gb_email', '$gb_homepage', '$gb_location', '$gb_entry_text', '$gb_entry_date', '$gb_mess_brand', '$gb_mess_nick', '$gb_user_ip', '$gb_user_host', '$gb_user_agent', '$gb_user_lang', '$gb_user_pass');";
mysql_query($insertstring);
mysql_close ($link);
session_register('gb_flood_ip');
session_register('gb_flood_last');
$gb_flood_ip = $gb_user_ip;
$gb_flood_last = time();
$msg = "<p class=\"messagetext\"><strong>" . $gb_fullname . "</strong><br><br>" . $gb_entry_text . "</p><p><a class=\"buttonview\" href=\"index.php\">$m_back</a><br></p>";
$msg = stripslashes($msg);
$msg = nl2br($msg);
if (($domain_emailnewentries == 'true') || ($domain_emailguest == 'true')) {
if (!$gb_email) {
$gb_emailfrom = $domain_emailadmin;
} else {
$gb_emailfrom = $gb_email;
}
$mailheaders = 'From: ' . $gb_fullname . ' <' . $gb_emailfrom . ">\n";
$mailheaders .= 'Reply-To: ' . $gb_fullname . ' <' . $gb_emailfrom . ">\n";
$gb_sendmail = $domain_title . $m_subject2 . $gb_fullname . "\n";
$gb_sendmail .= "__________________________________________________\n\n";
$gb_sendmail .= strip_tags(stripslashes($gb_entry_text));
$gb_sendmail .= "\n\n__________________________________________________\n";
$gb_sendmail .= 'date: ' . date("Y-m-d H:i:s") . "\n";
$gb_sendmail .= 'host: ' . $gb_user_host . "\n";
$gb_sendmail .= 'agent: ' . $gb_user_agent . "\n";
$gb_sendmail .= 'url: ' . $domain_url . '?uid=' . $gb_user_pass . "\n\n";
if ($domain_emailnewentries == 'true') {
@mail($domain_emailadmin, $m_subject1 . $domain_title, $gb_sendmail, $mailheaders);
}
if ($domain_emailguest == 'true' && $gb_email != '') {
$mailheaders = "From: " . $domain_title . " <" . $gb_emailadmin . ">\n";
$mailheaders .= "Reply-To: " . $domain_title . " <" . $gb_emailadmin . ">\n";
@mail($gb_email, $m_subject1 . $domain_title, $gb_sendmail, $mailheaders);
}
}
} elseif (($todo == 'add') && (!$gb_entry_text)) {
$msg = "<p class=\"messagetext\">$m_notext</p><p><a class=\"buttonview\" href=\"sign.php\">$m_back</a><br></p>";
}
#========================================
# This will happen if icon/button TRASH was clicked
#========================================
if (($todo == 'trash') && (!$gb_parole_try)) {
$msg = "<p class=\"messagetext\">$m_trash<strong> " . $name . "</strong>.";
$msg .= "<br>$m_password<br><br>";
$msg .= "<input type=\"hidden\" name=\"todo\" value=\"trash\">";
$msg .= "<input type=\"hidden\" name=\"gb_parole_status\" value=\"true\">";
$msg .= "<input type=\"hidden\" name=\"name\" value=\"$name\">";
$msg .= "<input type=\"hidden\" name=\"id\" value=\"$id\">";
$msg .= "<input type=\"password\" name=\"gb_parole_try\" maxlength=\"100\"></p>";
$msg .= "<p><input class=\"buttonsend\" type=\"submit\" value=\"$m_continue\"></p>";
}
if (($todo == 'trash') && ($id) && ($gb_parole_try)) {
if (($gb_parole_try == $gb_parole) || ($gb_parole_try == md5($gb_parole))) {
if (!$trashnow) {
$msg = "<p class=\"messagetext\"><strong>$m_confirmation</strong><br>";
$msg .= "<input class=\"radio\" type=\"radio\" name=\"trashnow\" value=\"false\" checked onFocus=\"if(this.blur)this.blur()\">$m_trashkeep $name<br>";
$msg .= "<input class=\"radio\" type=\"radio\" name=\"trashnow\" value=\"true\" onFocus=\"if(this.blur)this.blur()\">$m_trashnow $name<br></p><p>";
$msg .= "<input type=\"hidden\" name=\"todo\" value=\"trash\">";
$msg .= "<input type=\"hidden\" name=\"id\" value=\"$id\">";
$msg .= "<input type=\"hidden\" name=\"name\" value=\"$name\">";
$msg .= "<input class=\"buttonsend\" type=\"submit\" value=\"$m_continue\"></p>";
} elseif ($trashnow == 'true') {
$link = @mysql_connect ("$sql_host", "$sql_id", "$sql_pass")
or die ($sql_error);
@mysql_select_db("$sql_db");
$killstring = "DELETE from $sql_table WHERE gb_number='$id';";
@mysql_query($killstring);
@mysql_close ($link);
$msg = "<p class=\"messagetext\"><strong>" . $name . "</strong> $m_trashdone</p><p><a class=\"buttonview\" href=\"index.php\">$m_back</a><br></p>";
}
}
}
#========================================
# This will happen if icon COMMENT was clicked
#========================================
any help is appreciated!