Hi,
I have the following code which creates a captcha image and writes a encoded string to session, the problem is, when I create the session variable, it does not show up to the rest of the application - it essentially doesn't exist, however- the image shows up correctly. I have tested the sessions elsewhere and everything works fine, the problem seems to be this, any thing I create outside of the captcha include is invisible to the include and anything I create outside the include is invisible to the include, for example, if I create the variables in the form, the captcha include can't find them. does it have to do with the php being rendered as a png?
here is the code to create the captcha:
<?php
//Start the session for captcha
session_start();
//Now lets use md5 to generate a totally random string
$md5 = md5(microtime() * mktime());
/*
We dont need a 32 character long string so we trim it down to 5
*/
$string = substr($md5,0,5);
/*
create the image from a background image.
*/
$captcha = imagecreatefrompng($_SERVER['DOCUMENT_ROOT']."/images/global/captcha.png");
/*
Lets set the colours, the colour $line is used to generate lines.
Using a blue misty colours. The colour codes are in RGB
*/
$black = imagecolorallocate($captcha, 0, 0, 0);
$line = imagecolorallocate($captcha,233,239,239);
/*
Now to make it a little bit harder for any bots to break,
assuming they can break it so far. Lets add some lines
in (static lines) to attempt to make the bots life a little harder
*/
imageline($captcha,0,0,39,29,$line);
imageline($captcha,40,0,64,29,$line);
/*
Now for the all important writing of the randomly generated string to the image.
*/
imagestring($captcha, 5, 20, 10, $string, $black);
/*
Encrypt and store the key inside of a session
*/
$_SESSION['key'] = md5($string);
/*
Output the image
*/
header("Content-type: image/png");
imagepng($captcha);
?>
And here is how I call it:
<img src="/_includes/contact/captcha.php" alt="verification code" />
As an aside, this is tutorial code it apparently works for a lot of people.