php登录页面 session

标签 php mysql session

我已经创建了一个运行良好的注册页面,信息被插入到 mysql 中,但是当我想登录时,由于某种原因它没有引导我到 account.php。它说“重定向到:account.php 有人可以帮我处理代码吗?我已经把什么放在了 login.php 和 account.php

谢谢

登录.php

$submitted_username = ''; 
if(!empty($_POST)) 
{ 

    $query = " 
        SELECT 
            id,
            forename,
            surname,
            Studentid, 
            username,
            salt, 
            password, 

            email 
        FROM users 
        WHERE 
            username = :username 
    "; 

     $query_params = array( 
        ':username' => $_POST['username'] 
    ); 

    try 
    { 

        $stmt = $db->prepare($query); 
        $result = $stmt->execute($query_params); 
    } 
    catch(PDOException $ex) 
    { 

        die("Failed to run query: " . $ex->getMessage()); 
    } 

  not. 
     switch it to true. 
    $login_ok = false; 



    $row = $stmt->fetch(); 
    if($row) 
    { 

        $check_password = hash('sha256', $_POST['password'] . $row['salt']); 
        for($round = 0; $round < 65536; $round++) 
        { 
            $check_password = hash('sha256', $check_password . $row['salt']); 
        } 

        if($check_password === $row['password']) 
        { 

            $login_ok = true; 
        } 
    } 

 members-only page 
    //  again 
    if($login_ok) 
    { 

        unset($row['salt']); 
        unset($row['password']); 


        $_SESSION['user'] = $row; 

        // Redirect the user to the private members-only page. 
        header("Location: account.php"); 
        die("Redirecting to: account.php"); 
    } 
    else 
    { 

        print("Login Failed."); 


        $submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8'); 
    } 
} 

account.php

<?php 
    require("common.php"); 
    if(empty($_SESSION['user'])) 
    { 
        header("Location: Login.php"); 

        die("Redirecting to Login.php"); 
    } 
?> 

Hello <?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?>, secret content!<br /> 
<a href="edit_account.php">Edit Account</a><br /> 
<a href="logout.php">Logout</a>

最佳答案

先知道什么是die()

http://php.net/manual/en/function.die.php

您可能希望使用 JavaScript 重定向来执行此操作,因为您希望显示一条消息。

在 3 秒或任何你想要的 set_timeout() 中使用重定向脚本在你的页面上放置一个 JS。

关于php登录页面 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28613354/

相关文章:

php - 如何编写只要服务器启动就运行的脚本?

php - Insert 只存储第一个数字,其余的被忽略

php - 检查了查询、数据库、表名、列名等,还是不明白为什么会出现这个错误

php - Zend Framework 不活动后自动注销

CakePHP 2.0 session 超时过早

php - 从输入表单在 session 中存储一个 php 数组

php - DateTime::createFromFormat - 找不到两位数秒

mysql - mysql 查询困惑

session - 如何在同一个tomcat下共享存储在不同webapps session 中的数据

php - MacOs Sierra 上的 ini 文件在哪里?