求助 PHP验证码 @符号
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
session_start();
for($i=0;$i<4;$i++){
@$rand.=dechex(rand(1,15));//前面的这个@符号要是不加,图片就显示不出来。
}
@$_SESSION[check_pic]=$rand; //前面的@符号要是去掉的话这个就会报错 而且全是乱码。
$im=imagecreatetruecolor(100,30);
$bg=imagecolorallocate($im,0,0,0);
$te=imagecolorallocate($im,255,255,255);
imagestring($im,5,0,0,$rand,$te);
header("content-type:image/jpeg");
imagejpeg($im);
?>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
session_start();
if($_POST[code]){
if($_POST[code]==$_SESSION[check_pic]){
echo "验证码正确:".$_SESSION[check_pic];
}
else
{
echo "验证码错误";
}
}
?>
<form action="" method="post">
@@##@@<br>
验证码:<input type="text" name="code">
<input type="submit" value="提交">
</form>
for($i=0;$i<font color="#e78608">------解决方案--------------------</font><br>$rand.=<br><br>这个变量无赋值的情况使用,所以导致notice错误,图像是二进制,notice是文本,二者混合自然导致图片无法显示。<br><br>解决办法:<br>先给$rand赋值<br><br>$rand='';<br><br><br><font color="#e78608">------解决方案--------------------</font><br>
<a style="color:#f60; text-decoration:underline;" title="session" href="https://www.php.cn/zt/17098.html" target="_blank">session</a>_start();
$rand = '';
for($i=0;$i<font color="#e78608">------解决方案--------------------</font><br>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号