Squoll2
Постоялец
- Регистрация
- 2 Июн 2009
- Сообщения
- 80
- Реакции
- 15
- Автор темы
- #1
Люди добрые помогите установить капчу в этот код а точнее чтобы шла проверка при нажатии кнопки добавить
А вот сам пример кода проверки
PHP:
<?php
$res = $db->query("SELECT * FROM `rigonda_reserv` ORDER BY `id` DESC");
/* KCAPTCHA */ session_start();
if(isset($_POST['submit'])) {
$errors = array();
$required_fields = array('userName','userText','keystring');
$errors = array_merge($errors, check_required_fields_2($required_fields, $_POST));
$name = mysql_real_escape_string(strip_tags($_POST['userName']));
$text = mysql_real_escape_string(strip_tags($_POST['userText']));
if(empty($errors)) {
$qr = $db->query("INSERT INTO `rigonda_reserv` (`id`, `name`, `text`, `date`, `level`)
VALUES (0, '{$name}', '{$text}', curdate(), 0)");
checkQueryResult_2($qr, 'index.php?cat=6&act=resAdd', 'index.php?cat=6&act=resAddErr');
}
}
?>
<div id="wn">
<center>
<table cellspacing="0" cellpadding="0" border="0" height="316">
<tr>
<td valign="top" align="left">
<!------------->
<div style="width: 475px;">
<?php showContent(5); ?>
<div id="hrhr"></div>
<br />
</div>
<div id="wn" class="flexcroll" style="height: 190px; width: 455px;">
<div id="lyr1">
<?php if(mysql_num_rows($res) > 0): ?>
<table cellspacing="0" cellpadding="0" border="0">
<?php while($r = mysql_fetch_assoc($res)): ?>
<tr>
<td width="475">
<span class="name">
<i><?= $r['date'] ?></i>
—
</span>
<span>
<?php if($r['level'] == 1): ?>
<?php $hh = "<br /><br />"; ?>
<b style="color: red;"><?= $r['name'] ?></b>
<?php else: ?>
<?php $hh = "<br /><br />"; ?>
<b><?= $r['name'] ?></b>
<?php endif ?>
</span>
</td>
</tr>
<tr>
<td>
<span class="name">
<div style="width:430px; margin: 0; padding: 0; padding-left: 10px;"><?= $r['text'] ?></div>
</span>
<?= $hh ?>
</td>
</tr>
<?php endwhile ?>
</table>
<?php else: ?>
<?= $lnNoRes ?>
<?php endif ?>
</div>
</div>
</div>
</td>
</tr>
</table>
</center>
</div>
<div id="second" >
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>?cat=6">
<table style="padding-left: 27px;" cellspacing="0" cellpadding="0" border="0">
<tr>
<td align="right" valign="top">
<label for="userName"><?= $lnYourName ?>:</label>
</td>
<td style="width: 210px;" align="right">
<input style="width: 200px;" name="userName" type="text" id="userName" />
</td>
</tr>
<tr>
<td colspan="2" style="height: 5px;"></td>
</tr>
<tr>
<td align="right" valign="top">
<label for="userText"><?= $lnYourText ?>:</label>
</td>
<td style="width: 210px;" align="right">
<textarea style="width: 200px;" rows="7" name="userText" id="userText"></textarea>
</td>
</tr>
<tr>
<td align="right" valign="top">
</td>
<td style="width: 210px;" align="right">
<img src="/kcaptcha/?<?php echo session_name()?>=<?php echo session_id()?>">
</td>
</tr>
<tr>
<td align="right" valign="top">
</td>
<td style="width: 210px;" align="right">
<input type="text" name="keystring">
</td>
</tr>
<tr>
<td colspan="2" style="height: 5px;"></td>
</tr>
<tr>
<td align="right" colspan="2">
<input type="submit" name="submit" id="submit" value="<?= $lnResSend ?>" />
</td>
</tr>
</table>
</form>
<div style="padding-left: 40px;">
<? if (!empty($errors)) { display_errors($errors); } ?>
<?php
if(isset($_GET['act'])) {
$act = $_GET['act'];
if($act == "resAdd" OR $act == "resAddErr") {
if($act == "resAdd") {
print $lnResOk;
}
if($act == "resAddErr") {
print $lnResErr;
}
} else {
print $lnResPageErr;
}
}
?>
</div>
</div>
А вот сам пример кода проверки
PHP:
if(count($_POST)>0){
if(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] == $_POST['keystring']){
echo "Correct";
}else{
echo "Wrong";
}
}
unset($_SESSION['captcha_keystring']);
?>