一旦我从登录重定向到管理页面,PHP会话变量就没有转移到我的管理页面

时间:2018-01-31 09:35:12

标签: php session

我有一个登录页面;如果用户名和密码与数据库匹配将重定向到admin;但在管理页面上,我没有得到会话变量。 首先是我的登录页面:

const AWS = require("aws-sdk");

const docClient = new AWS.DynamoDB.DocumentClient({
    convertEmptyValues: true
});

然后是管理页面:

<?php
session_start(); //Start the session
session_regenerate_id(true); 
//print_r($_SESSION);
use Ct\Ct\Data\Data;
extract($_POST);
$eventlists = Data::getpassword();
foreach ($eventlists as $eventlist) {
    $get_list_username = $eventlist->user_name;
    $get_list_password = $eventlist->user_pass;
}
//echo $get_list_username.'outside'; 
if(isset($_POST['submit'])) {
    $your_name = $_POST['username'];
    $your_password = $_POST['password'];
    $_SESSION['usr'] = $your_name;
    $_SESSION['pwd'] = $your_password;
    //echo $_SESSION['username'];
    if($_SESSION['usr'] == $get_list_username && $_SESSION['pwd'] == $get_list_password) {
        print('<script>window.location.href="https://ct.org/admin-gunpage-update/"</script>');                  
    }
    else {
       echo '<center><b style="color:red;position: relative;left: -27%;">Invalide username or password, please check again!   </b></center>';             
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Login Gun Page Update</title>
</head>
<body>
<form name="login" id="login" method="POST" action="">
    <label class="log_in"> LOGIN </label>
    <p><label for="username" class="username">Username: </label><input type="text" size="100" name="username" id="username" value="" placeholder="UserName"/></p>
    <p><label for="password" class="password">Password: </label><input type="password" size="40" name="password" id="password" value="" placeholder="Password"/></p>
    <p><input type="submit" name="submit" id="submit" class="submit" value="Submit"/> <input type="reset" name="reset" id="reset" class="reset" value="reset"/></p>
</form>
</body>
</html>

我有一个登录页面;如果用户名和密码与数据库匹配将重定向到admin;但在管理页面上,我没有得到会话变量。 我做了<?php session_start(); //Start the session print_r($_SESSION); if(!isset($_SESSION['usr'])) // if there is no valid session { print('<script>window.location.href="https://ct.org/login-gun-page-updates/"</script>'); //echo 'NOT working !!'; } echo $_SESSION['usr']; use Ct\Ct\Data\Data; extract($_POST); if(isset($save)) { Data::getupdate($ticketsavailable); print('<script>window.location.href="https://ct.org/gun-drawing/"</script>'); } $ticketleft = ""; $ticketleft = Data::getticketsavailable(); //print_r($ticketleft); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>update page</title> </head> <body> <form action="" method="POST"> <label class="update_heading"> UPDATE TICKETS </label> <a href='https://ct.org/logout-gunpage-update-form/' class="logout_link" > Logout</a><br> <label for="update" class="update"> Update Number: </label><input type="textbox" id="ticketsavailable" name="ticketsavailable" value="<?php echo $ticketleft[0]->ticket_available; ?>"/><br><br> <input type="submit" name="save" value="Submit"> </form> </body> </html> 它在管理页面上显示为空。我已经开始在这两个页面的会议,请帮助!! 请帮助我没时间!!

1 个答案:

答案 0 :(得分:0)

我的建议是 首先登录然后在会话前($_SESSION['username']=$username);存储用户名访问密钥,并在登录成功后将用户访问权限存储在另一个会话变量($_SESSION['useraccess']="admin");中,将此会话用于其他网页