ted_chou12 Posted March 10, 2009 Share Posted March 10, 2009 Hello, I don't understand why this code doesnt work: <?php session_start(); //send img to header as jpg file header('Content-type: image/jpeg'); //generate random string: $alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $string = substr(str_shuffle($alphanum), 0, 5); //store in session (md5) $_SESSION['imgverify'] = md5($string); //create image from existing bgs $bgno = rand(1, 4); $image = imagecreatefromjpeg("images/background$bgno.jpg"); //white bg, black text $bgcolor = imagecolorallocate($image, 255, 255, 255); $textcolor = imagecolorallocate($image, 0, 0, 0); //producing image (img, font, x, y, text, color) imagestring($image, 5, 7, 8, $string, $textcolor); imagejpeg($image); imagedestroy($image);?> and <?php session_start(); //image verification passed? if ($_SESSION['imgverify'] != md5($imgverify)) {echo $imgverify_failed; $invalid = true;}?> <label>Image Verification</label> <img id="image" src="imgverify.php" onclick="reloadImg();" /> But the $_SESSION['imgverify'] is not md5 encoded in the second page, I have no idea what's wrong, ??? Thanks, Ted Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/ Share on other sites More sharing options...
redarrow Posted March 10, 2009 Share Posted March 10, 2009 md5($imgverify) << where this defined mate. Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-780910 Share on other sites More sharing options...
ted_chou12 Posted March 10, 2009 Author Share Posted March 10, 2009 md5($imgverify); is defined from an form submission above these codes, $imgverify = $_POST['imgverify']; Ted Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-781494 Share on other sites More sharing options...
ted_chou12 Posted March 12, 2009 Author Share Posted March 12, 2009 bump... Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-783301 Share on other sites More sharing options...
thebadbad Posted March 12, 2009 Share Posted March 12, 2009 Does $_SESSION['imgverify'] contain anything at all, at the second page? First thing to check. Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-783321 Share on other sites More sharing options...
ted_chou12 Posted March 12, 2009 Author Share Posted March 12, 2009 Yes, it has something, it's the uncoded string from the first page, but when i output the variable in the first page, the string is md5 coded ??? i have no clue why it's like this Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-783347 Share on other sites More sharing options...
ted_chou12 Posted March 15, 2009 Author Share Posted March 15, 2009 I found where the problem is, but i still have no clue why it is: //on the second page, where the submission of image verify code is: if (isset($_POST['submit'])){ $name = $_POST['name']; $email = $_POST['email']; $tname = $_POST['tname']; $temail = $_POST['temail']; $message = $_POST['message']; $imgverify = $_POST['imgverify'];//after here the $_SESSION['imgverify'] suddenly turns to non md5 coded, but before this line $_SESSION['imgverify'] is fine. I think this is a bug that ive found, i spent hours trying to look for this error, is so annoying... Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-784908 Share on other sites More sharing options...
thebadbad Posted March 15, 2009 Share Posted March 15, 2009 Not that I'm sure it would matter, but do you have register_globals turned on? Link to comment https://forums.phpfreaks.com/topic/148719-image-verification/#findComment-784980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.