javascript - 密码保护目录列表器

标签 javascript java php html

我正在制作一个目录列表器!

这是我的网站 Website

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

enter image description here

但现在我必须用密码保护该页面!我需要帮助如何做到这一点!

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

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

额外:

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

  • 访问目录
  • FTP 登录

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

最佳答案

是时候了解 $_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;

您放入 session 中的任何内容都仅适用于该用户。现在,在您网站的 protected 部分,您可以

<?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"

关于javascript - 密码保护目录列表器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31367842/

相关文章:

javascript - 选择标签中的 Mixitup 过滤器在 google chrome 和 IE 中不起作用

javascript - Browserify 转换插件用于评估 IIFE 并在捆绑期间替换为其结果

javascript - 如何将React Form的输入传递给axios get请求并显示请求结果?

java - Google PubSub 和来自 TOPIC 的重复消息

java - 当给定特定范围时,程序不会猜测正确的数字

javascript - Ajax 调用后脚本无法正常运行

javascript - 在 React 中旋转 3 页

java - 模拟测试依赖注入(inject)的对象

php - PUT请求的Amazon ElasticSearch服务签名不匹配-Amazon SDK PHP V2

php - 通过PHP将HTML表单数据插入mySQL(表单数组因表行数而异)