登录Php - 两个或更多会话

时间:2015-01-27 12:55:02

标签: php session login types

我有一个来自模板的登录代码,我想在代码中再添加两个会话,因此实际上有三个会话,一个用于管理员,成人和初级。我想代码通过php中设置的用户类型变量来选择会话。所以例如if user_type =" junior"那么位置是junior.php。代码本身:

<?php 
require("config.php"); 
$submitted_username = ''; 
if(!empty($_POST)){ 
    $query = " 
        SELECT 
            id, 
            username, 
            password, 
            salt, 
            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()); } 
    $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;
        } 
    } 

   if($login_ok){ 
        unset($row['salt']); 
        unset($row['password']); 
        $_SESSION['user'] = $row;  
        header("Location: secret.php"); 
        die("Redirecting to: secret.php"); 
    } 
    else{ 
        print("Login Failed."); 
        $submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8'); 
    } 
} 
?>     

我真的很挣扎,任何帮助都会受到赞赏,因为我是php的新手。

0 个答案:

没有答案