我有一个HTML表单,发送到PHP页面进行处理。我需要在表单中添加验证码。我无法将HTML页面更改为PHP,因此在captcha.php页面中设置会话,该页面以图像形式输出。当页面加载会话var设置但我无法在进程PHP页面中检索此会话时,会话为空。有人可以帮忙吗?
在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流程页面:
session_start();
print_r($_SESSION);
有人可以帮忙吗?
答案 0 :(得分:1)
尝试
print_r($_SESSION['code']);