一个实用的php验证码类
万能php验证码类,供大家参考,具体内容如下 code.php是验证码类,类的名称最好和文件名的名称一样,这样有利于我们的查看。 code.php public function __construct($number=4,$codeType=0,$height=50,$width=100){
//初始化自己的成员属性 $this->number=$number; $this->codeType=$codeType; $this->width = $width; $this->height= $height;
} test.php是new一个新的验证码,并把它保存到session中,为我们验证码的验证起到保存和存储的作用。 test.php $code= new Code(4,1,50,100);
$_SESSION['code']= $code->getCode(); $code->outImage(); login.php就是最后的验证。 login.php alert('验证码正确!');";
}else{
echo "";
}
}
?>
li{
padding:12px;
position:relative;
}
label{
width:80px;
display:inline-block;
float:left;
line-height:30px;
}
input[type='text'],input[type='password']{
height:30px;
}
img{
margin-left:10px;
}
input[type="submit"]{
margin-left:80px;
padding:5px 10px;
}
</style>
</head>
<body>
<form action="login.php" method="post">
<ul>
<li>
<label>用户名:</label>
<input type="text" name="username"/>
</li>
<li>
<label>密码:</label>
<input type="password" name="password"/>
</li>
<li>
<label>验证码:</label>
<input type="text" name="code" size="4" style="float:left"/>
<img src="test.php" onclick="this.src='test.php?Math.random()'"/>
</li>
<li>
<input type="submit" value="登录" name="dosubmit"/>
</li>
</ul>
</form>
</body>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |