[PHP] Captha Image Matching the Session Value.
Hi all, My captha code is working but the session code is not matching image code(captha code). How do i get them to match each other. PHP CAPTHA session_start(); $fontArray = array('arial.tff' , 'impact.tff' , 'tahoma.tff' , 'tunga.tff' , 'verdana.tff'); $fontOne = md5(rand(0,50)); $fontTwo = md5(rand(0,50)); $fontThree = md5(rand(0,50)); $fontFour = md5(rand(0,50)); //Let's generate a totally random string using md5 $md5_hashOne = md5(rand(0,999)); $md5_hashTwo = md5(rand(0,999)); $md5_hashThree = md5(rand(0,999)); $md5_hashFour = md5(rand(0,999)); //We don't need a 32 character long string so we trim it down to 5 $wordOne = substr($md5_hashOne, 15, 1); $wordTwo = substr($md5_hashTwo, 15, 1); $wordThree = substr($md5_hashThree, 15, 1); $wordFour = substr($md5_hashFour, 15, 1); //Set the image width and height $width = 400; $height = 150; //Create the image resource $image = @imagecreatefromjpeg(CapthaBack.jpg); $grey = imagecolorallocate($image, 255, 255, 255); imagettftext($image,20, rand(0,70), 30, 30, $grey , 'impact.ttf' , $wordOne); imagettftext($image,20, rand(0,70), 70, 30, $grey , 'impact.ttf' , $wordTwo); imagettftext($image,20, rand(0,70), 110, 30, $grey , 'impact.ttf' , $wordThree); imagettftext($image,20, rand(0,70), 150, 30, $grey , 'impact.ttf' , $wordFour); session_unset($_SESSION[security_code]); $_SESSION[security_code] = $wordOne . . $wordTwo . . $wordThree . . $wordFour; header(Content-Type: image/jpeg); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); HTML CODE session_start(); table tr td/td td colspan=2input type=text name=captha value=?php echo Test:.$_SESSION[security_code] ?/td /table Thanks, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21650616.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
On Sun, 2009-01-25 at 03:25 -0800, Stephen Alistoun wrote: Hi all, My captha code is working but the session code is not matching image code(captha code). How do i get them to match each other. PHP CAPTHA session_start(); $fontArray = array('arial.tff' , 'impact.tff' , 'tahoma.tff' , 'tunga.tff' , 'verdana.tff'); $fontOne = md5(rand(0,50)); $fontTwo = md5(rand(0,50)); $fontThree = md5(rand(0,50)); $fontFour = md5(rand(0,50)); //Let's generate a totally random string using md5 $md5_hashOne = md5(rand(0,999)); $md5_hashTwo = md5(rand(0,999)); $md5_hashThree = md5(rand(0,999)); $md5_hashFour = md5(rand(0,999)); //We don't need a 32 character long string so we trim it down to 5 $wordOne = substr($md5_hashOne, 15, 1); $wordTwo = substr($md5_hashTwo, 15, 1); $wordThree = substr($md5_hashThree, 15, 1); $wordFour = substr($md5_hashFour, 15, 1); //Set the image width and height $width = 400; $height = 150; //Create the image resource $image = @imagecreatefromjpeg(CapthaBack.jpg); $grey = imagecolorallocate($image, 255, 255, 255); imagettftext($image,20, rand(0,70), 30, 30, $grey , 'impact.ttf' , $wordOne); imagettftext($image,20, rand(0,70), 70, 30, $grey , 'impact.ttf' , $wordTwo); imagettftext($image,20, rand(0,70), 110, 30, $grey , 'impact.ttf' , $wordThree); imagettftext($image,20, rand(0,70), 150, 30, $grey , 'impact.ttf' , $wordFour); session_unset($_SESSION[security_code]); $_SESSION[security_code] = $wordOne . . $wordTwo . . $wordThree . . $wordFour; header(Content-Type: image/jpeg); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); HTML CODE session_start(); table tr td/td td colspan=2input type=text name=captha value=?php echo Test:.$_SESSION[security_code] ?/td /table Thanks, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21650616.html Sent from the PHP - General mailing list archive at Nabble.com. Is it possible the captcha image is being cached? Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
Hi ash, Thanks for your reply but the image does change when i refresh the page but the session value is one before the image value. If this is a cache problem how would i prevent this? Thanks, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21650839.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
... 1. It's captcha, not captha - http://en.wikipedia.org/wiki/Captcha 2. As far as I can see (and that's not too far), you appear to be sending HTML along with the image. You need to have one script to generate the page, and another to create and send the captcha image. -- Richard Heyes HTML5 Graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated January 17th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
Hey Richard, Thanks for your reply but the Captcha php code is a seperate file to the html code but the code is working but the values are not matching. Thanks, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21651034.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
On Sun, 2009-01-25 at 04:09 -0800, Stephen Alistoun wrote: Hey Richard, Thanks for your reply but the Captcha php code is a seperate file to the html code but the code is working but the values are not matching. Thanks, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21651034.html Sent from the PHP - General mailing list archive at Nabble.com. Have you tried outputting what the image text is (and commenting out the line that outputs the image) and comparing this directly with what is going in your session. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
Hey Ash, Is I have but the Session Value is one before the Captha Image Value. Regards, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21651258.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
At 4:33 AM -0800 1/25/09, Stephen Alistoun wrote: Hey Ash, Is I have but the Session Value is one before the Captha Image Value. Regards, Stephen Stephen: It's looks to me that your code is generating a CAPTCHA from a key, but your key is not being recorded in the SESSION as what is current. I had the same problem, but solved it by making sure that the key that was used to generate the CAPTCHA was the same key that was expected to be entered by the user. It's just a logic problem you have to work out. Here's some of what I did: http://webbytedd.com/aa/assorted-captcha/ Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
Stephen Alistoun wrote: Hi all, My captha code is working but the session code is not matching image code(captha code). How do i get them to match each other. PHP CAPTHA session_start(); $fontArray = array('arial.tff' , 'impact.tff' , 'tahoma.tff' , 'tunga.tff' , 'verdana.tff'); $fontOne = md5(rand(0,50)); $fontTwo = md5(rand(0,50)); $fontThree = md5(rand(0,50)); $fontFour = md5(rand(0,50)); //Let's generate a totally random string using md5 $md5_hashOne = md5(rand(0,999)); $md5_hashTwo = md5(rand(0,999)); $md5_hashThree = md5(rand(0,999)); $md5_hashFour = md5(rand(0,999)); //We don't need a 32 character long string so we trim it down to 5 $wordOne = substr($md5_hashOne, 15, 1); $wordTwo = substr($md5_hashTwo, 15, 1); $wordThree = substr($md5_hashThree, 15, 1); $wordFour = substr($md5_hashFour, 15, 1); //Set the image width and height $width = 400; $height = 150; //Create the image resource $image = @imagecreatefromjpeg(CapthaBack.jpg); $grey = imagecolorallocate($image, 255, 255, 255); imagettftext($image,20, rand(0,70), 30, 30, $grey , 'impact.ttf' , $wordOne); imagettftext($image,20, rand(0,70), 70, 30, $grey , 'impact.ttf' , $wordTwo); imagettftext($image,20, rand(0,70), 110, 30, $grey , 'impact.ttf' , $wordThree); imagettftext($image,20, rand(0,70), 150, 30, $grey , 'impact.ttf' , $wordFour); session_unset($_SESSION[security_code]); $_SESSION[security_code] = $wordOne . . $wordTwo . . $wordThree . . $wordFour; header(Content-Type: image/jpeg); //Output the newly created image in jpeg format ImageJpeg($image); //Free up resources ImageDestroy($image); HTML CODE session_start(); table tr td/td td colspan=2input type=text name=captha value=?php echo Test:.$_SESSION[security_code] ?/td /table Thanks, Stephen Pear has 3 very nice classes for generating and handling captchas. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
Hey guys sorry to interrupt but, the problem is rather obvious if you try and put the img src='captcha.php' / - which is the captcha image it self - anywhere in the script you are effectively overwriting the session variable - since you are initializing the form file session in the very beginning of the form file, and then calling the captcha file which over writes the session file, but that does not automatically update in the form file so there you get the old value. If you make the check if the text is correct after the submit of the form, it should be correct. I hope I have made myself clear enough. Petar Stephen Alistoun stephenalist...@gmail.com написа в съобщението news:21651258.p...@talk.nabble.com... Hey Ash, Is I have but the Session Value is one before the Captha Image Value. Regards, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21651258.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
Hey guys sorry to interrupt but, the problem is rather obvious if you try and put the img src='captcha.php' / - which is the captcha image it self - anywhere in the script you are effectively overwriting the session variable - since you are initializing the form file session in the very beginning of the form file, and then calling the captcha file which over writes the session file, but that does not automatically update in the form file so there you get the old value. If you make the check if the text is correct after the submit of the form, it should be correct. I hope I have made myself clear enough. Petar Stephen Alistoun stephenalist...@gmail.com написа в съобщението news:21651258.p...@talk.nabble.com... Hey Ash, Is I have but the Session Value is one before the Captha Image Value. Regards, Stephen -- View this message in context: http://www.nabble.com/Captha-Image-Matching-the-Session-Value.-tp21650616p21651258.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Captha Image Matching the Session Value.
Configure your browser to prompt you for cookies. That will make sure you are doing the session bit the way you think you are. Then add some error_log statements when you set or read the secret word. You'll soon figure out exactly how/why your session has the OLD secret word in it. -- Some people ask for gifts here. I just want you to buy an Indie CD for yourself: http://cdbaby.com/search/from/lynch -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php