密码保护目录列表

时间:2015-07-12 12:38:08

标签: javascript java php html html5

我正在创建Lister目录!

这是我的网站Website

我已经在这个网站上成功实现了PHP代码。

enter image description here

但现在我必须密码保护该页面!我需要帮助怎么做!

如果我制作一个简单的php / html文件重定向到目录列表,人们会看到该链接,并可以绕过输入密码,并将直接访问目录链接!

但是我必须锁定整个页面,我该怎么做!

额外:

我想首先打开一个页面,其中有两个按钮:

  • 访问目录
  • FTP登录

点击访问登录时会提示输入密码并进入目录!

1 个答案:

答案 0 :(得分:1)

了解$_SESSION$_POST

的时间

您可以通过以下两种方式之一验证用户/

$ _ SESSION

使用php在服务器上创建cookie和相应的用户数据信息,以确保您知道自己与谁通话。您必须使用此方法使用某种密码。

让有密码的页面转到提交页面

<form action="login.php" method="post">
    <input type="password" name="pass" />
    <input type="submit" />
</form>

login.php看起来像

<?php
session_start(); //this starts a session for any user visiting the page
if (!$_POST["pass"] === "mypassword") { //if the user got there with no password
    die(); //kill the page
}
//anything after here will only be shown to people who input "mypassword"
//at this point we can give the user a piece of data so they can access other
//parts of the site with
$_SESSION["auth"] = true;

您在会话中添加的任何内容都将仅针对该用户。现在,在您网站的受保护部分,您可以

<?php
session_start();
if (!$_SESSION["auth"]) {
    echo "you don't have priveleges to come here!";
    die();
}
//authenticated users continue to roped off part.

$ _ POST

您也可以像上面一样使用帖子,但如果用户离开您的网页,这样做就不会记住用户。 (他们必须重新登录)

if (!$_POST["pass"] === "mypassword") { //if the user got there with no password
    die(); //kill the page
}
//anything after here will only be shown to people who input "mypassword"