Jump to content

Recommended Posts

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?)

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>

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().

 

 

<?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;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.