metulj (23-06-10), something else (23-06-10)
here is a captcha code which i have developed for wap sites.
1. create a new file image.php and put the next code code to it:
create folder gumcha where the captcha image script is and chmod 777 it.PHP Code:<?php
@exec("find ./gumcha/ -maxdepth 1 -type f -mtime +1 -exec rm -f {} \;");
$code = rand_string(5);
file_put_contents('./gumcha/'.$code, $code);
function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyz123456789";
$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return $str;
}
/* YOU CAN MODIFY THE IMAGE CODE FROM HERE TO CREATE MORE COOL CAPTCHA IMAGES, eg. with different backgrounds */
header("Content-type: image/gif");
$im = @imagecreate(60, 25)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 3, 5, 5, $code, $text_color);
imagegif($im);
imagedestroy($im);
?>
and then use this peace of code which will check if the gumcha generated code is correct:
PHP Code:if($_POST){
$gumcha_code = $_POST['code'];
if(gumcha_check($gumcha_code) == true)
{
// HERE GOES THE CONTENT AFTER THE CAPTCHA VALIDATION
}else echo 'WRONG CAPTCHA CODE';
}
function gumcha_check($code)
{
$code = trim($code);
$code = str_replace('.','',$code);
$code = strtolower($code);
if (preg_match("/[^\da-z]+/", $code)) return false;
elseif(strlen($code)<2)return false;
elseif(file_exists('./gumcha/'.$code))
{
@unlink('./gumcha/'.$code);
return true;
}
else return false;
}
Advertise your mobile site for FREE with [Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
metulj (23-06-10), something else (23-06-10)
Nice, but what if someone evil would pass $_POST['code']= "../index.php"?
this is kinda dangerous....
it would be better to generate a numeric random code and use something like
@unlink('./gumcha/'.intval($gumcha_code));
I hope i explained myself
Cheers
GumSlone (23-06-10)
Originally Posted by Sora101 [Only registered and activated users can see links. Click Here To Register...]
will do the thingPHP Code:$gumcha_code = str_replace('.','',$gumcha_code);
or
code updatedPHP Code:if (preg_match("/[^\da-zA-Z]+/", $gumcha_code)))
$error = 'Wrong code.';
Advertise your mobile site for FREE with [Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
I can do it w/o session, sql or txt file..just submit the answer of the user and the correct answer to the 2nd page and then compare if equal..as easy as that..
lol there are many tuts out there on web thats why u just modify codes LOL...
com site: [Only registered and activated users can see links. Click Here To Register...]
download site: [Only registered and activated users can see links. Click Here To Register...]
fb: [Only registered and activated users can see links. Click Here To Register...]
You don't need tut if u use head or common sense..Be wise..Trust urself u can do it with ur own and learn with urself..If not, you don't deserve to be a good coder..
Last edited by kiLLeR-eyEd_14; 23-06-10 at 21:26.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks