【问题标题】:PHP Password Protect [closed]PHP密码保护[关闭]
【发布时间】:2012-07-20 15:52:30
【问题描述】:

我研究了这么久,我已经做了数百次了,但我现在忘记了。最简单的事情。如何在 PHP 中进行密码保护。请帮忙,当我点击提交时,什么都没有弹出。这是我的代码:

<html>
<style type="text/css">
#textbox1 {
text-shadow:2px 2px 3px #000000;
}

label {
text-shadow:2px 2px 3px #000000;
font-family:"Arial";
}
</style>
</style>
<script type="text/javascript">
function clearText(target){target.value= "";}
</script>
<head>
<center>
<form action="" method="POST">
<label face="Arial">Password:  </label><input id="textbox1" type="password" name="password" value="" onfocus="clearText(this)">
<input id="button" type="submit" value="Login to Uploader">
</form>
</center>
</html>
<?php

$pass = $_POST['password'];
$submit = $_POST['submit'];

if (isset($_POST['submit'])) {
if ($pass == "pengsuploader123" || $pass="pass") {
echo "Test";
} else {
echo "Wrong!";
}
}

?>

【问题讨论】:

  • name=submit 什么都没有,这就是为什么isset($_POST['submit'])===FALSE 总是
  • 你的 HTML 标记让我眼花缭乱。

标签: php forms passwords password-protection


【解决方案1】:

您需要为提交按钮提供name="submit" 属性,以便PHP 检测到它。此外,$pass="pass" 应该是 $pass == "pass"。

【讨论】:

  • 谢谢你!你能帮我做点别的吗/
  • @Ryan 你应该把它当作一个问题来问,而不是问一个特定的人,除非它与这段代码有关。
  • 是的。我想这样做,所以他们必须登录此表单才能查看特定页面。因此,他们必须进入通行证保护页面,如果输入正确的密码,他们就可以查看特定文档,并使其无法直接访问该文档。我无法提出新问题,因为我必须等待 20 分钟
  • 如果文档存储为外部可用,则需要使用 cookie/sessions 和 mod_rewrite,否则需要使用 readfile。有很多关于如何制作登录系统的教程。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-10
  • 2021-09-27
  • 2014-05-11
  • 1970-01-01
  • 2013-05-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多