Variable won't store in session
Posted
by
Mittens
on Stack Overflow
See other posts from Stack Overflow
or by Mittens
Published on 2012-06-28T15:05:28Z
Indexed on
2012/06/28
15:16 UTC
Read the original article
Hit count: 177
So I'm trying to store the "rank" of a user when they log in to a control panel which displays different options depending on the given rank. I used the same method as I did for storing and displaying the username, which is displayed on the top of each page and works just fine. I can't for the life of me figure out why it won't work for the rank value, but I do know that it is not saving it in the session. Here is the bit that's not working;
$username = ($_POST['username']);
$password = hash('sha512', $_POST['password']);
$dbhost = 'mysql:host=¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦;dbname=¦¦¦¦¦¦¦¦¦¦¦';
$dbuser = '¦¦¦¦¦¦¦¦¦¦¦';
$dbpassword = '¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦';
try {
$db = new PDO($dbhost, $dbuser, $dbpassword);
$statement = $db->prepare("select password from users where email = :name");
$statement->execute(array(':name' => $username));
$result = $statement->fetch();
$pass = $result[password];
$rank = $result[rank];}
catch(PDOException $e) {echo $e->getMessage();}
if ($password == $pass) {
session_start();
$_SESSION['username'] = $username;
$_SESSION['rank'] = $rank;
header('Location: http://¦¦¦¦¦¦¦¦¦.ca/manage.php');
}
else{
include'../../includes/head.inc';
echo '<h1>Incorrect username or password.</h1>';
include'../../includes/footer.inc';
}
I'm also new to the whole PDO thing, hence why my method of authenticating the password is pretty sketchy.
© Stack Overflow or respective owner