abbas27
دوشنبه 21 مهر 1393, 22:07 عصر
سلام بر دوستان-مشکل کد کپچای من چیه که کد رو درست وارد میکنم بعضی موقع میگه کد درسته بعضی موقع هم با اینکه کد امنیتی رو درست وارد میکنم میگه اشتباه است.
captch-ok.php
<?php
session_start();
function getRandomString(){
$length=6;
$characters='0123456789abcdefghijklmnopqrstuvwxyz' ;
$string='';
for($p=0;$p<$length;$p++){
$string.=$characters[mt_rand(0,strlen($characters))];
}
return $string;
}
header('Content-type: image/jpeg');
$_SESSION["secure"]= getRandomString();
$font_size=25;
$image_width=175;
$image_height=60;
$image= imagecreate($image_width,$image_height);
imagecolorallocate($image,200,180,50);
$text_color= imagecolorallocate($image,0,0,0);
for($x=1;$x<=100;$x++)
{
$x1=rand(1,150);
$y1=rand(1,100);
$x2=rand(1,500);
$y2=rand(1,150);
imageline($image,$x1,$y1,$x2,$y2,$text_color);
}
imagettftext($image, $font_size,10,20,50,$text_color,"oldsans.ttf",$_ SESSION['secure']);
imagejpeg($image);
?>
ins.php
<?php
session_start();
<?php
if($_POST['reg'])
{
//*****************************
if(empty($captch_filter))
{$num=0;
echo '<font color="#EC070A">کد امنیتی را وارد نمایید!!! </font>';
exit();
}
if(ctype_alnum ($captch_filter)==false)
{$num=0;
echo '<font color="#EC070A">کد امنیتی مورد نظر شامل عدد و حرف باید باشد.!!! </font>';
exit();
}
if($_POST['reg'])
{
if(($_POST['captcha'])!=($_SESSION['secure']))
{
echo '<font color="#EC070A">کد امنیتی صحیح نمیباشد!!! </font>';
echo $_SESSION['secure'];
exit();
}
else
{
echo "ok captcha";
echo $_SESSION['secure'];
exit();
}
}
?>
post.js
$(document).ready(function(){
$("#change_captcha").click(function(){
$("#as_captcha").attr("src", "object/captch-ok.php?"+Math.random());
});
});
$(document).ready(function() {
$("#reg").click(function(){
$("#result").html('<strong>لطفا صبر نماییدpleas waith</strong>');
var reg=$("#reg").val();
var capt=$("#captcha").val();
$.post("object/ins.php",{reg:reg,captcha:capt},function(data) {$("#result").html(data);});
});
$("#reg").click(function(){
$("#as_captcha").attr("src", "object/captch-ok.php?"+Math.random());
});
});
captch-ok.php
<?php
session_start();
function getRandomString(){
$length=6;
$characters='0123456789abcdefghijklmnopqrstuvwxyz' ;
$string='';
for($p=0;$p<$length;$p++){
$string.=$characters[mt_rand(0,strlen($characters))];
}
return $string;
}
header('Content-type: image/jpeg');
$_SESSION["secure"]= getRandomString();
$font_size=25;
$image_width=175;
$image_height=60;
$image= imagecreate($image_width,$image_height);
imagecolorallocate($image,200,180,50);
$text_color= imagecolorallocate($image,0,0,0);
for($x=1;$x<=100;$x++)
{
$x1=rand(1,150);
$y1=rand(1,100);
$x2=rand(1,500);
$y2=rand(1,150);
imageline($image,$x1,$y1,$x2,$y2,$text_color);
}
imagettftext($image, $font_size,10,20,50,$text_color,"oldsans.ttf",$_ SESSION['secure']);
imagejpeg($image);
?>
ins.php
<?php
session_start();
<?php
if($_POST['reg'])
{
//*****************************
if(empty($captch_filter))
{$num=0;
echo '<font color="#EC070A">کد امنیتی را وارد نمایید!!! </font>';
exit();
}
if(ctype_alnum ($captch_filter)==false)
{$num=0;
echo '<font color="#EC070A">کد امنیتی مورد نظر شامل عدد و حرف باید باشد.!!! </font>';
exit();
}
if($_POST['reg'])
{
if(($_POST['captcha'])!=($_SESSION['secure']))
{
echo '<font color="#EC070A">کد امنیتی صحیح نمیباشد!!! </font>';
echo $_SESSION['secure'];
exit();
}
else
{
echo "ok captcha";
echo $_SESSION['secure'];
exit();
}
}
?>
post.js
$(document).ready(function(){
$("#change_captcha").click(function(){
$("#as_captcha").attr("src", "object/captch-ok.php?"+Math.random());
});
});
$(document).ready(function() {
$("#reg").click(function(){
$("#result").html('<strong>لطفا صبر نماییدpleas waith</strong>');
var reg=$("#reg").val();
var capt=$("#captcha").val();
$.post("object/ins.php",{reg:reg,captcha:capt},function(data) {$("#result").html(data);});
});
$("#reg").click(function(){
$("#as_captcha").attr("src", "object/captch-ok.php?"+Math.random());
});
});