【发布时间】:2017-09-15 03:48:42
【问题描述】:
我将 smarty 与 codeigniter 一起使用。我的刷新验证码在 chrome 中可以正常工作并更改验证码的图片,但它在 Firefox 中不起作用,我的验证码也没有改变。
我的部分观点:
<script>
function refreshCaptcha() {
$("#captcha_code").attr('src','{$url}Login/captcha');
}
</script>
</head>
<form class="m-t" role="form" action="{$url}admin/Dashboard"
method="POST">
<img id="captcha_code" src="{$url}Login/captcha" />
<a name="submit" class="btnRefresh" onClick="refreshCaptcha();">Refresh
Captcha</a>
</form>
我的控制器:
public function captcha()
{
$image = @imagecreatetruecolor(120, 30) or die("Cannot Initialize new GD
image stream");
$background = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
imagefill($image, 0, 0, $background);
$linecolor = imagecolorallocate($image, 0xCC, 0xCC, 0xCC);
$textcolor = imagecolorallocate($image, 0x33, 0x33, 0x33);
for($i=0; $i < 6; $i++)
{ imagesetthickness($image, rand(1,3));
imageline($image, 0, rand(0,30), 120, rand(0,30), $linecolor);}
session_start();
$digit = '';
for($x = 15; $x <= 75; $x += 20)
{ $digit .= ($num = rand(0, 9));
imagechar($image, rand(3, 5), $x, rand(2, 14), $num, $textcolor);
$_SESSION['captcha_code'] = $digit;
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
}
【问题讨论】:
标签: javascript php codeigniter captcha