0

成功登录后(即用户在输入用户名和密码后单击登录按钮),根据用户类型,我想将用户发送到特定页面。下面是我的代码。(这里,如果usertype是'employee',他应该在点击'login'按钮后被带到“data-update.php”页面。)

这是 index.php 页面中的代码:

// This file is the home page.

// Require the configuration before any PHP code as the configuration controls error reporting:
require ('config.inc.php');

// The config file also starts the session.

// Require the database connection:
require (MYSQL);

// If it's a POST request, handle the login attempt:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    include ('login.inc.php');
}

/* PAGE CONTENT STARTS HERE! */
?>
<!DOCTYPE html>
<html lang="en">
<head>
...

这是 login.inc.php 页面中的代码:

<?php 

// This is the login page for the site.
// It's included by index.php, which receives the login form data.

// Array for recording errors:
$login_errors = array();

// Validate the username:


// Validate the password:


if (empty($login_errors)) { // OK to proceed!

// Query the database:
$q = "SELECT id, type FROM users WHERE (username='$u' AND pass='"  .  get_password_hash($p) .  "')";        
$r = mysqli_query ($dbc, $q);

if (mysqli_num_rows($r) == 1) { // A match was made.

    // Get the data:
    $row = mysqli_fetch_array ($r, MYSQLI_NUM); 

    // Store the data in a session:
    $_SESSION['user_id'] = $row[0];
    $_SESSION['username'] = $u;     

    if ($row[1] == 'employee') {
        reset_sms_update_session();
        header("Location: http://".BASE_URL."data-update.php");                         
        exit;
    }
    elseif ($row[1] == 'client'){
        header("Location: http://".BASE_URL."About.html");
        exit;
    }

...

这是“data-update.php”页面中的部分代码:

 // Start the session:
 session_start();

function redirect_invalid_user($check = 'user_id', $destination = 'index.php', $protocol = 'http://') {

// Check for the session item:
if (!isset($_SESSION[$check])) {
    $url = $protocol . BASE_URL . $destination; // Define the URL.
    header("Location: $url");
    exit(); // Quit the script.
}

} // End of redirect_invalid_user() function.

//Redirect to index.php if user not logged in
redirect_invalid_user( );

/* PAGE CONTENT STARTS HERE! */
?>
<!DOCTYPE html>

...

问题是,在谷歌浏览器中,当用户单击登录按钮时,他首先被带到 index.php 页面(发生重定向的地方),然后他必须再次单击登录按钮才能被带到“data-update.php “ 页。为什么在 Google Chrome 中会发生这种情况?(仅供参考:这不会发生在我本地 PC 的 XAMP 测试环境中。)

这不会在 Firefox 或 IE8 中发生(即用户在第一次单击登录按钮时会被带到“data-update.php”)。

请帮忙。

4

1 回答 1

0

http://example.com我通过在我的网络服务器中为to设置来自 CPanel 的永久重定向来解决这个问题http://www.example.com

于 2012-11-24T10:07:28.807 回答