<?php header("Content-type:text/html;charset=utf-8"); //判断验证码是否与服务端一样 if(isset($_REQUEST['authcode'])){ session_start(); if($_REQUEST['authcode']==$_SESSION['authcode']){ echo "<font color='#0000CC'>输入正确</font>"; }else{ echo "<font color='#CC0000'><b>输入错误</b></font>"; } exit(); } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>验证码</title> </head> <body> <form method="post" action="./form.php"> <p> 验证码图片: <img id="captcha_img" border="1" src="./captcha.php?r=<?php echo rand()?>" width="100" height="50"> <a href="javascript:void(0)" onclick= "document.getElementById('captcha_img').src='./captcha.php?r='+Math.random()">看不清楚?</a> </p> <p>请输入图片中的内容:<input type="text" name="authcode" value="" /></p> <p><input type="submit" value="提交" style="padding:6px 20px"></p> </body> </html>
这位兄弟说的很对。要在captcha.php文件的头部写上session_start();
<?php
session_start();
很有可能你的另外一个文件的顶部没有写session_start(); 这个函数