Vermillion Posted May 16, 2009 Share Posted May 16, 2009 I have been coding my site for months now, and weeks on just the registration script. Today, I had planned to finally finish my registration script, but I noticed that there's a problem with my captcha scripts thanks to the fact that my Ajax wouldn't deliver the correct Captcha. So trying to hunt the bug down, I started to make the script, and surprisingly, I found the bug very quickly, but unfortunately I still can't find a solution for it. This is the script that outputs the Captcha image: <?php session_start(); // Everything related to the Captcha. $captchamd5 = md5(microtime() * mktime()); $string = substr($captchamd5, 0, 7); //The Captcha string will only have 7 characters. $captcha = imagecreatefrompng("../graphics/captcha_bg.png"); $white = imagecolorallocate($captcha, 255, 255, 255); $line = imagecolorallocate($captcha, 233, 239, 239); imageline($captcha, 0, 0, 39, 29, $line); imageline($captcha, 40, 0, 64, 29, $line); imagestring($captcha, 5, 20, 10, $string, $white); $_SESSION['captcha'] = $string; header("Content-type: image/png"); imagepng($captcha); ?> And the test page I made to test it just has this code: <?php session_start(); ?> <?php echo '<img src="AwingsCLF/register/captcha.php"/>'; echo $_SESSION['captcha']; ?> Like you can see, the first script assigns the value to my $_SESSION['captcha'] array value, and the second script echoes that output, but first including the captcha as an image. The problem is that the values on the Captcha are different; what I echo is different than what I see in the image, like you can see on the pic below: Any help with this will be really appreciated. I don't want to change the way the whole thing works because I have a complex PHP class that handles registrations that comes from both browsers with JS enabled and for browsers without it. So I really need to get that session variable working right. Quote Link to comment https://forums.phpfreaks.com/topic/158348-help-me-with-this-simple-captcha-script/ Share on other sites More sharing options...
RussellReal Posted May 16, 2009 Share Posted May 16, 2009 I've made a simple captcha which is fully operational and I give it out, session.php holds the value of the image for the session, captcha.php shows the image.. you show the image, then compare the supplied text from the user, with the text in session.php [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/158348-help-me-with-this-simple-captcha-script/#findComment-835121 Share on other sites More sharing options...
Vermillion Posted May 16, 2009 Author Share Posted May 16, 2009 I really appreciate it but I have checked your code and I came to the conclusion that I can't adapt it to mine, so can you just help me to get mine right? Your code scared me when I saw it had references, and I already suck with pointers in C++, so I may just check them another day . I just really need to see why when I echo the $_SESSION['captcha'] variable it is different than the captcha in the picture. I mean, both strings are the same variable, and I don't modify it in any other line after I create it. Quote Link to comment https://forums.phpfreaks.com/topic/158348-help-me-with-this-simple-captcha-script/#findComment-835126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.