Posted by Squet34785 on 08/09/06 21:11
Hello,
I'm trying to make a function that caches whether or not the user is an
administrator using a session variable. I've tried the below:
function isAdministrator($username){
session_start();
if (!session_is_registered("isAdministrator")) {
session_register("isAdministrator");
$db = connectdb();
$sql = "select username from users where username='$username' and
type='Admin'";
$result = mysql_query($sql, $db);
if (mysql_num_rows($result) > 0) {
$isAdministrator = true;
}else{
$isAdministrator = false;
}
}
return $isAdministrator;
}
but it always comes back false. Is the session scoped to the function? The
function is within an external subs file.
Navigation:
[Reply to this message]
|