Cardale Posted November 6, 2009 Share Posted November 6, 2009 I have been working on building a captcha, but I am running into a problem. My session variable that is storing the value isn't being set. I have already started a session. What could be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/180613-solved-setting-session-inside-captcha/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2009 Share Posted November 7, 2009 If 20,013 different people wrote code to build a captcha system, they could have all written the post you just made above and there could be something different wrong in each of their programs. What could be the problem? There's something wrong either in your code (what have you done to troubleshoot it to pin down at what point it works and at what point it does not) or on your server (sessions don't work at all, have you confirmed that any usage of session variables work or is it only something in your code?) Quote Link to comment https://forums.phpfreaks.com/topic/180613-solved-setting-session-inside-captcha/#findComment-952905 Share on other sites More sharing options...
Cardale Posted November 7, 2009 Author Share Posted November 7, 2009 I was hoping for some kind of insight for people who have built captchas with imagecreatefromjpeg(). I have done severnal tests and I am stumped. I have started a session at the start of my "page" and the captcha also has a session start inside it and for some reason they don't conflict, which is strange to me since I expected an error. This lead me to believe captchas don't work the same way. I thought maybe I needed to pass the session variable I used at the bottom of my captcha in a different location. I am doing the basic captcha with a include file that is really basic basic. I try and store the value in a session at the end of the page so I can double check what the person entered with the actual value of the picture.... <img src=captcha.php> Quote Link to comment https://forums.phpfreaks.com/topic/180613-solved-setting-session-inside-captcha/#findComment-952910 Share on other sites More sharing options...
DavidAM Posted November 7, 2009 Share Posted November 7, 2009 It's not real clear where your problem lies. My session variable that is storing the value isn't being set. which script is storing the value and which script is not seeing it? When I did this it seems like I ran into a problem because both scripts could be executing at the same time. If the main script has not finished before the browser requests the captcha script, the session has not been updated and the captcha script does not see it. I resolved this problem by putting everything into the session variables and calling session_close() BEFORE starting the output to the browser. That way the session data is written to the session file and the captcha script can get it when it calls session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/180613-solved-setting-session-inside-captcha/#findComment-952975 Share on other sites More sharing options...
Cardale Posted November 7, 2009 Author Share Posted November 7, 2009 <?php session_start(); $randomstring = md5(microtime()); $realstring = substr($randomstring,0,5); $useimage = imagecreatefromjpeg("img.jpg"); $linecolor = imagecolorallocate($useimage,233,239,239); $textcolor = imagecolorallocate($useimage, 255, 255, 255); imageline($useimage,1,1,40,40,$linecolor); imageline($useimage,1,100,60,0,$linecolor); imagestring($useimage, 5, 20, 10, $realstring, $textcolor); header("Content-type: image/jpeg"); imagejpeg($NewImage); $_SESSION['key'] = $realstring; ?> Quote Link to comment https://forums.phpfreaks.com/topic/180613-solved-setting-session-inside-captcha/#findComment-953298 Share on other sites More sharing options...
Cardale Posted November 7, 2009 Author Share Posted November 7, 2009 I got it. Now if I can just figure out some ajax methods. Quote Link to comment https://forums.phpfreaks.com/topic/180613-solved-setting-session-inside-captcha/#findComment-953310 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.