php登陆时检测是否有特殊字符

登陆框写的简单,主要是判断输入的值中是否有特殊字符

<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">&nbsp;</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()">&nbsp;
	<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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值