【问题标题】:session protection 3 [duplicate]会话保护 3 [重复]
【发布时间】:2013-03-21 20:27:44
【问题描述】:

我正在一点一点地创建一个网页,测试部分网页创意。我想学习如何会话保护页面。我已经对页面进行了密码保护,但是任何人都可以通过输入 url 来访问该页面。我想会话保护我的页面,所以没有人可以做到这一点。我有三个页面:index.html,它具有发送password.php的表单,password.php,它使用“if statments”确保密码和用户名是正确的(这里是“if statment”)

    if ($username == 'mgmb99'){
    if ($password == 'mgmb91mas'){
    header('Location: youhere.php');
    } else {
    echo 'your username or password is wrong.<a href="http://www.passwordtest.comze.com"> go back to login page </a>';
    }} else {
    echo 'your username or password is wrong.<a href="http://www.passwordtest.comze.com"> go back to login page </a>';
    };

,以及登录后的页面 youhere.php。

【问题讨论】:

  • 不要重复你的问题。使用任何新信息(您未在此处提供。如果有的话,这比您使用 less 信息的其他问题更糟)更新您的原始问题。在发布新问题之前,请查看about Stack Overflow
  • @JohnConde 他已经打开了这个问题,我不建议回到上一个问题,像这样忽略这个问题。

标签: php session passwords password-protection


【解决方案1】:

网上有很多很好的例子。但是会话限制(和数据库)最好使用盐键或哈希。

所以基本上你需要一个 id/用户名和一段随机文本,然后(例如)用 sha1 对其进行散列。

sha1($[your username].'completely random piece of text')

这将为您提供一个 40 个字符的字符串,如果您有用户名和随机文本,您可以复制该字符串。所以:

if($SESSION['id'] == sha1($[your username].'完全随机的一段文字')) { // 现在你知道用户名是正确的 }

基本上就是这样。它确实有一些更多的技巧。但永远不要在会话中放入任何对任何人都有意义的东西。因此,只需在会话中使用公共 ID(不是用户 ID)以及散列数据。

这里有一个简单的 SESSION 示例(没有检查它,但它很好开始):http://www.webdesign.org/web-programming/php/password-protect.11092.html

祝你好运!

【讨论】:

    【解决方案2】:
    do like this
    <?php
    session_start();
    if ($username == `enter code here`)
    {
        if ($password == `mgmb91mas`)
        {
          $_SESSION[`id`]='Secret code';
          header(`Location:page.php`);
        }
    ?>
    and check that id in the next page at start like below
    <?php
    session_start();
    if($_SESSION['id']!='Secret code')
    {
    header('Location:inde.php');
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 2010-12-04
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2021-01-05
      • 2016-07-17
      • 2017-03-23
      相关资源
      最近更新 更多