<td>验证码 :</td>
<td><input type=”text” name=”yzm”style=”width:60px;height:20px;” /><img src=”code.php”
onclick=”javascript:this.src=’code.php?’+Math.random();”></img></td>
</tr>
<tr> <td colspan=’2′><input type=”submit” value=”注册”/></td>
<td>验证码 :</td>
</tr>
因为是用
post 提交的,所以我们用$_POST 来获取(在接受页面做验证码的验证:post.php
页面)
代码如下
Session_start();
//back_alert()验证码输入错误的时候,弹出错误信息
function back_alert($yzm){
echo “<script type=’text/javascript’>alert(‘$yzm’);history.back();</script>”;
}
//禁止恶意调用(禁止直接在浏览器打开 post.php 页面)
if($_POST["yzm"]==null){
back_alert(‘你都木有输入验证码,有木有???’); }
// 禁止恶意注册
if(!($_POST["yzm"]==$_SESSION["Checknum"])){
back_alert(‘验证码不正确’);
} echo $_POST["yzm"];