无法获取登录页面重定向到安全页面 [英] Trouble getting login page to redirect to secure page

查看:130
本文介绍了无法获取登录页面重定向到安全页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用php创建的登录页面,在正确登录后,我有一个问题需要我将其带到管理页面。我知道我使用的登录名是正确的,因为我刚创建它,如果它是错的,它应该告诉我。但是,一旦我登录,整个页面就会变成空白,并且网址显示我仍然在登录页面而不是管理页面。

I have a login page I created using php, and I'm having an issue getting it to take me to the admin page after I've logged in correctly. I know the login I'm using is correct, since I just created it, and if it's wrong, it's supposed to tell me. However, once I login, the whole page just goes blank and the web address says I'm still on the login page instead of the admin one.

我检查了错误日志和它说PHP的警告:不能修改标题信息 - 已在第4行/admin/includes/functions.php(输出在/admin/login.php:6开始输出)发送的标头

I checked the error log and it says "PHP Warning: Cannot modify header information - headers already sent by (output started at /admin/login.php:6) in /admin/includes/functions.php on line 4"

这是错误日志所指的代码:

This is the code the error log is referring to:

    function redirect_to($new_location) {
    header("Location: " . $new_location);
    exit;
}

我不明白错误指出了什么。在我学习如何创建登录页面和管理页面时,我已经使用了这个确切的代码,并且当我在我的计算机上使用WAMP进行测试时,我没有任何问题。现在,我已经把它放在我的网站的服务器上,这个错误正在出现。我不确定从何处开始排除故障,因为如果我取出该功能,那么它根本不会重定向。任何帮助将被超级赞赏!!

I don't understand what the error is pointing out. I've used this exact code before when I was learning how to create a login and admin pages, and I didn't have any problems when I tested it out then using WAMP on my computer. Now that I've put it on my website's server, this error is popping up. I'm not sure where to begin troubleshooting because if I take out that function, then it won't redirect at all. Any help would be super appreciated!!

这是我用于登录页面的主要代码,如果有帮助:

Here is the main code I'm using for the login page, if that helps:

<?php require_once("includes/session.php"); ?>
<?php require_once("includes/db_connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/validation_functions.php"); ?>

<?php
$username = "";
if (isset($_POST['submit'])) {
// Process the form

// validations
$required_fields = array("username", "password");
validate_presences($required_fields);

if (empty($errors)) {
    // Attempt Login

    $username = $_POST["username"];
    $password = $_POST["password"];

    $found_admin = attempt_login($username, $password);

    if ($found_admin) {
            // Success
            // Mark user as logged in
            $_SESSION["admin_id"] = $found_admin["id"];
            $_SESSION["username"] = $found_admin["username"];
            redirect_to("http://thehummingbirdplace.com/admin/admin.php");
    } else {
            // Failure
            $_SESSION["message"] = "Username/password not found.";
    }
}
} else {
// This is probably a GET request

}   // end: if (isset($_POST['submit']))

?>

<?php $layout_contect = "admin"; ?>
<?php include("includes/layouts/header.php"); ?>
<div id="main">
<div id="navigation">
    &nbsp;
</div>
<div id="page">
    <?php echo message();  ?>
    <?php echo form_errors($errors); ?>

    <h2>Login</h2>
    <form action="login.php" method="post">
        <p>Username:
            <input type="text" name="username" value="<?php echo htmlentities($username); ?>" />
        </p>
        <p>Password:
            <input type="password" name="password" value="" />
        </p>
        <input type="submit" name="submit" value="Submit" />
    </form>
 </div>
</div>

<?php include("includes/layouts/footer.php"); ?>


推荐答案

事情是,头函数应该在调用之前任何输出都会发送到浏览器。

The thing is, the header function should be called before any output is sent to the browser.

尝试使用此代替header():

Try using this in place of the header():

echo '<meta HTTP-EQUIV="REFRESH" content="0; url='.$new_location.'">';

这篇关于无法获取登录页面重定向到安全页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆