登陆框写的简单,主要是判断输入的值中是否有特殊字符
<html>
<head>
<meta http-equiv="content-type" content="text/html charset=uft-8"/>
<title></title>
<style>
label{
text-align:right;
margin-right:450px;
float:right;
margin-top:15px;
width:80px;
}
input[name=user]{
margin-left:80px;
margin-top:-22px;
margin-bottom:10px;
width:150px;
}
input[name=pwd]{
margin-left:80px;
margin-top:-22px;
margin-bottom:10px;
width:150px;
}
* html input{
margin-left:80px;
margin-top:-30px;
margin-bottom:10px;
width:150px;
}
</style>
</head>
<body>
<form name="form1" method="post" action="">
<table width="532" height="183" align="center" border="1" cellpadding="0" cellspacing="0" broder="#FFCC33">
<tr>
<td height="71" colspan="2" align="center"> </td></tr>
</tr>
<tr>
<td width="281" align="left">
<label>用户名:</label><input name="user" type="text" id="user" size="20"><br>
<label>密码:</label><input name="pwd" type="password" id="pwd" size="20">
</td>
</tr>
<tr>
<td height="43" align="center">
<input type="submit" name="submit" value="登录" onclick="check()">
<input type="reset" name="submit2" value="重置">
</td>
</tr>
</table>
</form>
<?php
@$user=$_POST['user'];
@$pwd=$_POST['pwd'];
if($user!=''&&$pwd!=''){ //判断是否为空
if(trim($user)&&strlen($user)<=12){ //去掉用户名两头的空格及用户名小于12个字符
$arr=str_split($user); //用str_split分割字符成数组,一个字符成一个数组值
$con="^/&*?%$#@\'\".,"; //包含了基本的特殊字符串
$a='';
foreach($arr as $value){ //foreach循环出用户名单个数组值
if(strstr($con,$value)){ //用strstr查找这个值是否在特殊字符串中,如果有则$a=1
$a=1;
}
}
if($a==1){
echo "<script>alert('有敏感字符');</script>";
exit;
}else{
echo "用户名:".$user."<br>密码:".$pwd;
}
}else{
echo "不能大于12个字符";
exit;
}
}
?>
<script> //用javascript检查是否为空,这里就不详述
function check(){
var form1=document.forms[0];
var user=form1.elements['user'];
var pwd=form1.elements['pwd'];
if(user.value==""){
alert('用户名不能为空!');user.focus();return false;
}
if(pwd.value==""){
alert('密码不能为空');pwd.focus();return false;
}
}
</script>
</body>
</html>