Witam
Chcialem dodać do formularza reklamowego mały antyspam, więc najpierw znalazlem go w jakimś shoutboxie, i mniej więcej wszystko skopiowałem. I tu pojawia się problem. Nie wiem czy wszystko działa poprawnie. I druga sprawa: chce, aby jeśli ktoś wpisze źle kod lub nie wpisze go wcale żeby wywalało bląd. Daje kody tego shoutboxa i formularza
Shoutbox:
<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright 2002 - 2005 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
if (!defined("IN_FUSION")) { header("Location:../../index.php"); exit; }
openside($locale['120']);
if (isset($_POST['post_shout'])) {
if (iMEMBER) {
$shout_name = $userdata['user_id'];
} elseif ($settings['guestposts'] == "1") {
$shout_name = trim(stripinput($_POST['shout_name']));
$shout_name = preg_replace("(^[0-9]*)", "", $shout_name);
if (isNum($shout_name)) $shout_name="";
}
$shout_message = str_replace("\n", " ", $_POST['shout_message']);
$shout_message = preg_replace("/^(.{255}).*$/", "$1", $shout_message);
$shout_message = preg_replace("/([^\s]{25})/", "$1\n", $shout_message);
$shout_message = trim(stripinput(censorwords($shout_message)));
$shout_message = str_replace("\n", "<br>", $shout_message);
if ($_POST['validation'] != "" && $_POST['validation'] == $_POST['validation_answer'])
{
if ($shout_name != "" && $shout_message != "") {
if (dbcount("(*)", "shoutbox", "shout_message='$shout_message' AND shout_datestamp+84600>".time())) {
header("Location: ".FUSION_SELF.(FUSION_QUERY ? "?".FUSION_QUERY : ""));
} else {
$result = dbquery("INSERT INTO ".$db_prefix."shoutbox VALUES('', '$shout_name', '$shout_message', '".time()."', '".USER_IP."')");
}
}
header("Location: ".FUSION_SELF.(FUSION_QUERY ? "?".FUSION_QUERY : ""));
}
else {
echo "<div style='text-align:center'>You must answer the maths question correctly for your shoutbox entry to be added. This is to prevent bots from spamming the shoutbox. We apologise for the inconvenience.<br /><br /></div>";
}
}
// Calculate random equation and answer
$var1 = rand(1,5);
$var2 = rand(1,5);
$equation = $var1 . " + " . $var2 . ":";
$validation_answer = $var1 + $var2;
if (iMEMBER || $settings['guestposts'] == "1") {
echo "<form name='chatform' method='post' action='".FUSION_SELF.(FUSION_QUERY ? "?".FUSION_QUERY : "")."'>
<table align='center' cellpadding='0' cellspacing='0'>
<tr>
<td colspan='2'>\n";
if (iGUEST) {
echo $locale['121']."<br>
<input type='text' name='shout_name' value='".$userdata['user_name']."' class='textbox' maxlength='32' style='width:140px;'><br>
".$locale['122']."<br>\n";
}
echo "<textarea name='shout_message' rows='4' class='textbox' style='width:140px;'></textarea>
</td>
</tr>
<tr>
<td align='right' class='tbl'>".$equation."</td>
<td class='tbl'>
<input type='text' name='validation' value='' class='textbox' style='width:50px'>
<input type='hidden' name='validation_answer' value='$validation_answer' class='textbox' style='width:50px'>
</td>
</tr>
<td><input type='submit' name='post_shout' value='".$locale['123']."' class='button'></td>
<td align='right' class='small'><a href='".INFUSIONS."shoutbox_panel/shoutboxhelp.php'>".$locale['124']."</a></td>
</tr>
</table>
</form>
<br>\n";
} else {
echo "<center>".$locale['125']."</center><br>\n";
}
$result = dbquery("SELECT count(shout_id) FROM ".$db_prefix."shoutbox");
$numrows = dbresult($result, 0);
$result = dbquery(
"SELECT * FROM ".$db_prefix."shoutbox LEFT JOIN ".$db_prefix."users
ON ".$db_prefix."shoutbox.shout_name=".$db_prefix."users.user_id
ORDER BY shout_datestamp DESC LIMIT 0,".$settings['numofshouts']
);
if (dbrows($result) != 0) {
$i = 0;
while ($data = dbarray($result)) {
echo "<span class='shoutboxname'>";
if ($data['user_name']) {
echo "<a href='".BASEDIR."profile.php?lookup=".$data['shout_name']."' class='side'>".$data['user_name']."</a>\n";
} else {
echo "".$data['shout_name']."\n";
}
echo "</span><br>
<span class='shoutboxdate'>".showdate("shortdate", $data['shout_datestamp'])."</span><br>
<span class='shoutbox'>".parsesmileys($data['shout_message'])."</span><br>\n";
if ($i != $numrows) echo "<br>\n";
}
if ($numrows > $settings['numofshouts']) {
echo "<center>\n<img src='".THEME."images/bullet.gif'>
<a href='".INFUSIONS."shoutbox_panel/shoutbox_archive.php' class='side'>".$locale['126']."</a> <img src='".THEME."images/bulletb.gif'></center>\n";
}
} else {
echo "<div align='left'>".$locale['127']."</div>\n";
}
closeside();
?>
Formularz (pogrubieniem zaznaczyłem to co próbowałem modyfikować):
<?
/*----------------------------------------------------+
| Reklama - Formularz przesłania danych
+------------------------------------------------------+
|Copyright © 2007
|Maciej 'Desloch' Markiewicz
|http://www.game-arena.pl
+------------------------------------------------------
| Tested with PHP-Fusion v6 and EP v. IV
+-----------------------------------------------------*/
require_once "maincore.php";
require_once "subheader.php";
require_once "side_left.php";
include LOCALE.LOCALESET."reklama.php";
[b]$var1 = rand(1,5);
$var2 = rand(1,5);
$equation = $var1 . " + " . $var2 . ":";
$validation_answer = $var1 + $var2;[/b]
if (isset($_POST['sendmessage'])) {
$mailname = substr(stripinput(trim($_POST['mailname'])),0,50);
$email = substr(stripinput(trim($_POST['email'])),0,100);
$subject = substr(str_replace(array("\r","\n","@"),"",stripslash(trim($_POST['subject']))),0,50);
$message = stripslash(trim($_POST['message']));
[b]$validation = stripslash(trim($_POST['validation_answer']));[/b]
if ($mailname == "") {
$error .= "· <span class='alt'>".$locale['420']."</span><br>\n";
}
if ($email == "" || !preg_match("/^[-0-9A-Z_\.]{1,50}@([-0-9A-Z_\.]+\.){1,50}([0-9A-Z]){2,4}$/i", $email)) {
$error .= "· <span class='alt'>".$locale['421']."</span><br>\n";
}
if ($subject == "") {
$error .= "· <span class='alt'>".$locale['422']."</span><br>\n";
}
if ($message == "") {
$error .= "· <span class='alt'>".$locale['423']."</span><br>\n";
}
[b]if ($validation == "") {
$error .= "· <span class='alt'>".$locale['420']."</span><br>\n";[/b]
}
if (!$error) {
require_once INCLUDES."sendmail_include.php";
sendemail($settings['siteusername'],$settings['siteemail'],$mailname,$email,$subject,$message);
opentable($subject);
echo "<center><br>\n".$locale['440']."<br><br>\n".$locale['441']."</center><br>\n";
closetable();
} else {
opentable($locale['400']);
echo "<center><br>\n".$locale['442']."<br><br><br>\n$error<br>\n".$locale['443']."</center><br>\n";
closetable();
}
} else {
opentable($locale['400']);
if (isset($_GET['subject']) && $_GET['subject']!="") $subject = stripinput(stripslash($_GET['subject'])); else $subject="";
if (isset($_GET['message']) && $_GET['message']!="") $subject = stripinput(stripslash($_GET['message'])); else $message="";
echo $locale['401']."<br><br>
<form name='userform' method='post' action='".FUSION_SELF."'>
<table align='center' cellpadding='0' cellspacing='0' class='tbl'>
<tr>
<td width='100'>Adres Twojej Strony: </td>
<td><input type='text' name='mailname' maxlength='50' class='textbox' style='width: 200px;'></td>
</tr>
<tr>
<td width='100'>Twój Adres E-Mail: </td>
<td><input type='text' name='email' maxlength='100' class='textbox' style='width: 200px;'></td>
</tr>
<tr>
<td width='100'>Rodzaj Reklamy: </td>
<td><select type='textbox' name='subject' maxlength='50' class='textbox' style='width: 200px;' value='".$subject."'><option value='Wymiana Bannerem'>Wymiana Bannerem</option>
<option value='Wymiana Buttonem'>Wymiana Buttonem</option>
<option value='Wymiana Linkiem Tekstowym'>Wymiana Linkiem Tekstowym</option></select>
</tr>
</tr>
<tr><td valign='top' width='90'>Kod Reklamy (HTML): </td>
<td><pre><textarea name='message' rows='10' class='textbox' style='width: 320px'>".$message."</textarea></pre></td>
</tr>
<tr>
[b]<td align='right' width='40'>".$equation."</td>
<td><input type='text' name='validation' value='' class='textbox' style='width:50px'>
<input type='hidden' name='validation_answer' value='$validation_answer' class='textbox' style='width:50px'>[/b]
</td>
</tr>
<tr>
<td align='center' colspan='2'>
<input type='submit' name='sendmessage' value='".$locale['406']."' class='button'>
</td>
</tr>
</table>
</form>\n";
closetable();
}
require_once "side_right.php";
require_once "footer.php";
?>
Z góry dzięki za pomoc
PW od moderatora:
- Przeniesienie tematu - Pieka 17.09 - 19:25
|