简单登陆界面(信息有效性过滤)

页面一:

<form method="post" action="33-2.php">
Fullname:<input type='text' name='username' value=''/><br />
Password:<input type='password' name='password'/><br/>
C o d e s :<input type='text' name='code'/>1234<br />
EmailAd :<input type='text' name='email'/><br/>
Contents: <textarea rows=5 cols=25 name='content'></textarea><br />
<input type="submit" value='Submit it!' name='send'/><br/>
</form>

效果:

页面二:

<?php

//设置页面编码
header('Content-Type:text/html;charset=gbk');

//1.先验证是否是33-1.php提交过来的
//用isset()判断存在性,点击按钮提交的,就说明其他超级全局变量都存在;否则跳回到33-1.php的界面
if(!isset($_POST['send']) || $_POST['send']!='Submit it!'){ 	//如果不是点击按钮提交或者点击的不是submit is!按钮
	header('location:33-1.php');					
	exit;							//跳转到33-1.php页面,且不在执行下面的代码
}

//2.接收所有数据,并过滤
$username = trim($_POST['username']);
$password = $_POST['password'];
$code = trim($_POST['code']);
$email = trim($_POST['email']);
$content = htmlspecialchars(trim($_POST['content']));

//3.做判断
//用户名不能小于2位,不能大于10位
if(strlen($username)<2||strlen($username)>10){
//	header('location:33-1.php');		//直接跳转不友好
	echo "<script>alert('Username can not <2 or >10');history.back();</script>";
	exit;
}else{
}

//密码不能小于6位
if(strlen($password)<6){
	echo "<script>alert('the password can not <6');history.back();</script>";
	exit;
}else{
}

//验证码必须是4位,且必须是数字
if(strlen(strlen($code)!=4||!is_numeric($code))){
	echo "<script>alert('the code must be 4 and must be numeric');history.back();</script>";
	exit;
}else{
}

//email格式,用正则表达式判断
if(!preg_match('/([\w\.]{2,255})@([\w\-]{1,255}).([a-z]{2,4})/',$email)){
	echo "<script>alert('the mail address is not aviable!');history.back();</script>";
	exit;
	}else{	
	}
	
//4.输出所有信息
echo 'Username is:'.$username.'<br />';
echo 'Password is:'.$password.'<br />';
echo 'Code is:'.$code.'<br />';
echo 'Email is:'.$email.'<br />';
echo 'Content is:'.$content.'<br />';

?>

结果:

转载于:https://my.oschina.net/cuffica/blog/74476

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值