入门菜鸟级别,现在想做一个验证邮箱不能为空的页面,变量名为$em
直接输出
if (empty($em)){
echo "<script>alert('不能为空');location.href='verify.php'</script>";
}
弹出框点击跳转后还是弹出框,无法跳转回跳转前页面,后来看了正确代码为
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>验证邮箱</title>
</head>
<body>
<center>
<form action="verify.php" method="post">
请输入邮箱:
<input type="text"name="em">
<input type="submit"value="提交">
</form>
<hr/>
</center>
</body>
</html>
<?php
header("conten-type:text/html;charset=utf8");
$em=isset($_POST['em'])?$_POST['em']:null;
if($em!==null){
if($em===""){
echo "<script>alert('不能为空');location.href='verify.php'</script>";
}
}?>
如何理解
if($em!==null){
if($em===""){
echo "<script>alert('不能为空');location.href='verify.php'</script>";
}
这部分?
php大神,问一个验证跳转的问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- Go 旅城通票 2017-05-13 09:39关注
你php代码和html是同一个页面的?
如果是第一次访问get请求$em为null,if (empty($em))成立执行location.href=''跳转访问同一个页面还是get访问,继续为null又跳转这样死循环了
所以要加if($em!==null)的判断,如果有POST提交了em这个键值,再判断值是否为空的,防止死循环
要么你的html另外一个页面,不要和验证通过页面,跳转到另外的一个页面就不会死循环了
解决 无用评论 打赏 举报
悬赏问题
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作