我有一个发送到 PHP 页面进行处理的 HTML 表单。我需要在表单中添加验证码。我无法将 HTML 页面更改为 PHP,因此在 captcha.php 页面中设置了一个会话,该页面输出为图像。当页面加载会话变量时,我无法在进程 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);
有人可以帮忙吗?