I have a HTML form that is sent to a PHP page to process. I need to add a captcha to the form. I cannot change the HTML page to PHP and so have set a session in a captcha.php page which outputs as an image. When the page loads the session var is set but I cannot retrieve this session in the process PHP page, the session is empty. Can anyone assist?
Code that sets session in the captcha.php:
session_start(); // start a session
$image = imagecreate(50, 20); //create blank image (width, height)
$bgcolor = imagecolorallocate($image, 0, 0, 0); //add background color with RGB.
$textcolor = imagecolorallocate($image, 255, 255, 255); //add text/code color with RGB.
$code = rand(1000, 9999); //create a random number between 1000 and 9999
$_SESSION['code'] = $code; //add the random number to session 'code'
imagestring($image, 10, 8, 3, $_SESSION['code'], $textcolor); //create image with all the settings above.
header ("Content-type: image/png"); // define image type
imagepng($image); //display image as PNG
PHP process page:
session_start();
print_r($_SESSION);
Can anyone assist?