mysql - PHP $_SESSION value is not setting correctly -
i have simple login page in php looks provided username , password in mysql database , sets php $_session variable if user found. works fine mostly, except $_session['user_type_id'] has value of 1 no matter value of $row[0]["user_type_id"].
var_dump ($row[0]["user_type_id"]) in code below confirms has correct value, var_dump($_session) (alongside first var_dump) shows $_session['user_type_id'] 1.
the $row value int while $_session value string, don't know if relevant. thing can think of i'm resetting session variable somewhere else don't recall doing , can't find happening anywhere.
i'm trying use value control permissions. can see i'm going wrong?
here session code
public static function new_session ($username, $pw, $inactive) { $db = mydb::getconnection(); $statement = $db->prepare('select * users username = :parameter1 , `password` = :parameter2'); $statement->bindvalue(':parameter1', $username); $statement->bindvalue(':parameter2', $pw); $statement->execute(); $row = $statement->fetchall(); var_dump ($row[0]["user_type_id"]); if (count($row) == 1) { session_start(); ini_set('session.gc_maxlifetime', 60 * 20); $_session['name'] = $row[0]['username']; $_session['id'] = $row[0]['id']; $_session['user_type_id'] = $row[0]["user_type_id"]; $_session['max'] = $inactive; $_session['timeout'] = time() + $inactive; $_session['loggedin'] = true; return true; } else { return false; } }
here output of var_dump ($row[0]['user_type_id'])
int(500)
and here output of var_dump ($_session['user_type_id'])
string(1) "1"
edit: below output of var_dump($result), suggested below @user3314428
array(5) { ["id"]=> int(2) ["user_type_id"]=> int(500) ["username"]=> string(5) "shane" ["password"]=> string(8) "***" ["email"]=> string(13) "***@***.**"
}
var_dump ($_session['user_type_id'] still string(1) "1"
i don't causing problem here. use type of format login.
if(!isset($_session) session_start(); public static function new_session ($username, $pw, $inactive) { $db = mydb::getconnection(); $statement = $db->prepare('select * users username = :parameter1 , `password` = :parameter2'); $statement->bindvalue(':parameter1', $username); $statement->bindvalue(':parameter2', $pw); $statement->execute(); if($statement->rowcount()==1) { $result = $statement->fetch(pdo::fetch_assoc); $_session['user_type_id']=$result['user_type_id']; $_session['var2']= $result['var2']; //and on }
Comments
Post a Comment