undefined index: user
Posted: Thu Oct 11, 2012 1:39 am
new member here, ...when im trying to try a simple code then i have encountered a undefined index: error ... i would like to know on how to fix this error.. thanks in advance.
with this code auth.php
<?php
$users = array(
"admin" => "adminpass",
"member1" => "member1pass"
);
//Returns true if $username and $password are valid
function credentials_valid($username, $password){
global $users;
return isset($users[$username]) &&
$users[$username] == $password;
}
//Logs into the user $user
function log_in($user){
$_SESSION['user'] = $user;
}
//Returns the currently logged in user (if any)
function current_user(){
return $_SESSION['user'];
}
?>
with this code auth.php
<?php
$users = array(
"admin" => "adminpass",
"member1" => "member1pass"
);
//Returns true if $username and $password are valid
function credentials_valid($username, $password){
global $users;
return isset($users[$username]) &&
$users[$username] == $password;
}
//Logs into the user $user
function log_in($user){
$_SESSION['user'] = $user;
}
//Returns the currently logged in user (if any)
function current_user(){
return $_SESSION['user'];
}
?>