-1

我正在尝试在我们的网站上创建一个相当简单但有效的维护设置。该功能应该工作的方式是,如果用户登陆网站上的任何页面,除了 fromhttps://www.ourbusiness.org/assets/home2.do/unlock-maintenance并且https://www.ourbusiness.org/legal/allheader()功能将启动并将用户重定向到https://www.ourbusiness.org/error/offline/. 我已经看过其他问题,尤其是这个问题,但在这个问题中,我认为可以改进;通过添加如此少量的代码。

所以首先是我们的config.php文件:

配置.运行.php:

<?php
define("URL", "https://www.ourbusiness.org");
define("MAINTENANCE", "1");

if(MAINTENANCE == 1) {
    if(!isset($_SESSION['MAINTENANCE_UNLOCK'])) {
        header("Location: ".URL."/error/offline/");
    }
}

解锁-maintenance.php

<?php
    include "Config.Run.php";
    session_start();

    if(isset($_POST)) {
        if($_POST['username'] == "admin" && $_POST['password'] == "admin") {
            $_SESSION['MAINTENANCE_UNLOCK'] = md5($_POST['username'].$_POST['password']);
            header("Location: ".URL."");
        }
    }
?>
<form action="" method="post">
    <h1>You are not logged in</h1>
    <b>Username: </b><input type="text" name="username" />
    <b>Password: </b><input type="password" name="password" />
    <input type="text" value="Unlock <?php echo TITLE; ?>" />
</form>

为什么这不起作用?我什至无法访问该文件来解锁网站或目录中的任何页面legal

4

2 回答 2

0

简短的回答是......

session_start();

if(isset($_POST)) {
    if($_POST['username'] == "admin" && $_POST['password'] == "admin") {
        $_SESSION['MAINTENANCE_UNLOCK'] = md5($_POST['username'].$_POST['password']);
        header("Location: ".URL."");
    }
}

include "Config.Run.php";

还..在另一个脚本上做..

if(MAINTENANCE == 1 && !isset($_SESSION['MAINTENANCE_UNLOCK'])) {
        header("Location: ".URL."/error/offline/");
    }
}

..把这些换成这样。我知道我应该包括细节,但它们在评论中。

于 2015-10-09T20:54:29.270 回答
-1

请注意,如果有人决定使用它,它不是最安全的身份验证系统

在修改了我们的代码后,我已经解决了这个问题——我想出了一个解决方案,它非常有效。请在下面查看我们的结果:

在我们的Config.Run.php内部:

define("URL", "https://www.ourbusiness.org");
define("MAINTENANCE", "1");

if(MAINTENANCE == 1) {
    if(!isset($_SESSION['MAINTENANCE_UNLOCK'])) {
        $current_file = explode('/', getcwd());
        $current_file = end($current_file);
        if ($current_file !== 'unlock-maintenance' && $current_file !== 'offline') {
            header("Location: ".URL."/error/offline/");
            exit();
        }
    }
}

在我们的解锁维护目录中(默认文件index.php

<h2>Maintenance log in</h2>
<?php
if(isset($_POST) && !empty($_POST)) {
    if($_POST['username'] == "admin" && $_POST['password'] == "admin") {
        $_SESSION['MAINTENANCE_UNLOCK'] = md5($_POST['username'].$_POST['password']);
        header("Location: ".URL."");
    } else {
        echo '<p class="err_msg">That login attempt failed, please try again.</p>';
    }
} else {
    echo '<p>You must login using your username and password.</p>';
}

?>
<form action="" method="post">
    <div class="input_group">
        <label>Username</label>
        <input type="text" class="input" name="username" value="">
    </div>
    <div class="input_group">
        <label>Password</label>
        <input type="password" class="input" name="password" value="">
    </div>
    <input type="submit" value="Login" />
</form>

我希望这对那些一直在寻找一个相当好的维护系统的人有所帮助。

请记住,您可以向此添加注销链接添加更多功能,更改页眉/页脚包含取决于是否登录等。

于 2015-10-09T21:43:06.170 回答