| |
|
|
| | Здравйствуйте...
Вообщем вот форма...
<form method="post"><table>
<tr><td><input type='text' name='code'></td></tr>
<tr><td><img src='captcha.php' /></td></tr>
<br><input type='submit' value='Проверить' name='go'></td></tr>
</table></form>
|
А вот код каптчи
<?php
$r = rand(1000000,9999999);
for($i = 0; $i < 7; $i++) {
$arr[$i] = substr($r,$i,1);
}
$im = imagecreate(130,40);
imagecolorallocate($im,255,255,255);
$a = 0;
for($i = 0; $i < 7;$i++)
{
$color=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagestring($im,3,$a+=15,0,$arr[$i],$color);
}
header("Content-type: image/jpeg");
imagejpeg($im,'',100);
?>
|
Вообщем мне надо сделать проверку того что пользователь ввел в форму с кодом который выводиться на картинке....
Говорят с сессиями, но код никто н е может сказать...
Помогите плз | |
| |
|
|
| |
|
|
| |
для: SnooPI
(24.04.2007 в 23:57)
| | | Сделал еще так:
form.php
<?php
session_start();
?>
<img src="captcha.php" />
<form method="post">
Enter code : <input type="text" name="get_code">
<input name="sub" type=submit value="Проверить">
</form>
<?php
if($_POST['sub']) {
if($_POST['sub'] == $_SESSION['code']) {
echo "Картинка введена верно";
} else {
echo "Картинка введена неверно";
}
}
?>
|
captcha.php
<?php
session_start();
session_register('code');
$_SESSION['code'] = rand(1000000,9999999);
for($i = 0; $i < 7; $i++) {
$arr[$i] = substr($_SESSION['code'],$i,1);
}
$im = imagecreate(130,40);
imagecolorallocate($im,255,255,255);
$a = 0;
for($i = 0; $i < 7;$i++)
{
$color=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagestring($im,3,$a+=15,0,$arr[$i],$color);
}
header("Content-type: image/jpeg");
imagejpeg($im,'',100);
?>
|
Все равно пишет что ввел неверный кодд...поомгите плз..что я н так с сессяями сделал?:( | |
| |
|
|
| |
|
|
| |
для: SnooPI
(25.04.2007 в 01:25)
| | |
Enter code : <input type="text" name="get_code">
<input name="sub" type=submit value="Проверить">
</form>
<?php
if($_POST['sub']) {
if($_POST['sub'] == $_SESSION['code']) {
|
введенный код будет в $_POST['get_code'] а $_POST['sub'] - кнопка)) | |
| |
|
|
| |
|
|
| |
для: SnooPI
(25.04.2007 в 01:25)
| | | генерация картинки
<?php
session_start();
$LETTERS = array("q","w","e","r","t","y",
"u","p","a","s","d","f","g","h","j","k",
"z","x","c","v","b","n","m","Q","W","E",
"R","T","Y","U","P","A","S","D","F","G",
"H","J","K","L","Z","X","C","V","B","N",
"M","2","3","4","5","6","7","8","9");
$src = imagecreatetruecolor(200,50);
$fon = imagecolorallocate($src,255,255,255);
imagefill($src,0,0,$fon);
$x=2;
for ($i=0;$i<=100;$i++)
{
$color = imagecolorallocatealpha($src,rand(0,255),rand(0,255),rand(0,255),200);
imagearc($src,rand(5,195),rand(5,45),10,10,rand(0,360),rand(0,360),$color);
}
for ($i=0;$i<=5;$i++)
{
$leter=$LETTERS[rand(1,(count($LETTERS)-1))];
$color = imagecolorallocate($src,rand(0,200),rand(0,200),rand(0,200));
$x=$x+rand(1,3)+25;
imagettftext($src,20,rand(-30,30),$x,rand(25,40),$color,'font.ttf',$leter);
$code[]=$leter;
}
$_SESSION['s']=md5(strtolower(implode('',$code)));
header ("Content-type: image/png");
imagepng($src);
imageDestroy($src);
?>
|
проверка кода
<?
session_start();
?>
<form action="" method="post">
<img src="getpng.php" border="0">
<input type="text" name="s" title="Введите код, который изображен на картинке" align="absmiddle">
<input type="submit" value="Проверить">
</form>
<?
if (!empty($_POST['s']))
{
if (md5(strtolower($_POST['s']))==$_SESSION['s']) echo "Код верен";
elseif (md5(strtolower($_POST['s']))!=$_SESSION['s']) echo "Неверен";
}
?>
|
| |
| |
|
|
|