我有这个captcha.php
文件,我在页面上加载我希望使用jQuery加载显示验证码。
在captcha.php
文件中,我开始一个新会话,并设置一个变量(theCaptchaCode
),其中包含您在图像上看到的代码,但是当我尝试使用{{获取会话变量时1}}。它说
undefined index:theCaptchaCode。
Captcha.php代码:
$theCaptchaCode = $_SESSION['theCaptchaCode']
答案 0 :(得分:0)
在代码末尾删除session_destroy()
方法。
<强>编辑:强> 使用以下代码:
<?php session_start();
$theCaptchaCode = "";
$thisCaptchaImg = imagecreatetruecolor(200, 50);
$color = imagecolorallocate($thisCaptchaImg, 0, 0, 0);
$dotColor = imagecolorallocate($thisCaptchaImg, 46, 46, 46);
$backgroundColor = imagecolorallocate($thisCaptchaImg, 255, 255, 255);
imagefilledrectangle($thisCaptchaImg, 0, 0, 200, 70, $backgroundColor);
$characters = '123456789QWERTYUIOPASDFGHJKLZXCVBNM';
$length = strlen($characters);
for($l=0;$l < 4;$l++)
{
imageline($thisCaptchaImg, 0, rand()%50, 200, rand()%50, $color);
}
for($d=0;$d < 1500;$d++)
{
imagesetpixel($thisCaptchaImg, rand()%200, rand()%50, $dotColor);
}
for($c=0;$c < 7;$c++)
{
$selCharacter = $characters[rand(0, $length-1)];
imagestring($thisCaptchaImg, 5, 5+($c*30), 20, $selCharacter, $color);
$theCaptchaCode .= $selCharacter;
}
imagepng($thisCaptchaImg, 'thisCaptchaImage.png');
$_SESSION['theCaptchaCode'] = $theCaptchaCode;
?>