ja660k Posted December 6, 2008 Share Posted December 6, 2008 hey guys, im having a problem making session variables. i have a login page and in it it has 2 "classes" of users, normal and super, and i do a check in my code and it assigns session variable accordingly, but when i print_r($_SESSION) the variable didnt work. here is my code function login($username,$password){ $xml = simplexml_load_file("data/xml/users.xml") or die ("Fatal Error opening file"); $auth = $xml->xpath("user/username[text()='$username']/../password[text()='$password']/.."); // navigate to username and check if is same as entered username; do same for password. if($auth[0] !=null){ // if auth found value if($xml->user->type == super){ // check if user is super user (faculty) $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['validAdminUser'] = true; }else if($xml->user->type == normal){ // if not check if normal user $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['validUser'] = true; } }else{ // if auth did not find values $error = "Invalid Username or password"; } return $error; } and the xml for this looks like this <users> <user> <type>normal</type> <username>ja660k</username> <password>admin</password> <firstName>zzzz</firstName> <lastName>qqqqq</lastName> </user> <user> <type>super</type> <username>admin</username> <password>admin</password> <firstName>xxxx</firstName> <lastName>yyyy</lastName> </user> </users> and when i try to login as admin the print_r returns Array ( [submit] => [username] => admin [password] => admin [validUser] => 1 ) instead of validuser, i need it to be validAdminUser like in the above php..? can anyone help Link to comment https://forums.phpfreaks.com/topic/135741-making-new-session-variables/ Share on other sites More sharing options...
mrMarcus Posted December 6, 2008 Share Posted December 6, 2008 perhaps you're not logging in correctly? maybe it's trying to tell you something. Link to comment https://forums.phpfreaks.com/topic/135741-making-new-session-variables/#findComment-707259 Share on other sites More sharing options...
ja660k Posted December 6, 2008 Author Share Posted December 6, 2008 hrmmm the only thing i could think of is changing $xml->user->type in the condition to $auth->type but that worked even less i have no idea Link to comment https://forums.phpfreaks.com/topic/135741-making-new-session-variables/#findComment-707261 Share on other sites More sharing options...
mrMarcus Posted December 6, 2008 Share Posted December 6, 2008 i really know squat about xml .. how about $xml->users->user->type? Link to comment https://forums.phpfreaks.com/topic/135741-making-new-session-variables/#findComment-707269 Share on other sites More sharing options...
ja660k Posted December 6, 2008 Author Share Posted December 6, 2008 i dont think so, cos using xpath method is automatically points in the parent, i might jsut have to add a guard in the xpath one for normal users and super users so i need 2 xpath's Link to comment https://forums.phpfreaks.com/topic/135741-making-new-session-variables/#findComment-707286 Share on other sites More sharing options...
ja660k Posted December 6, 2008 Author Share Posted December 6, 2008 thankyou for making me think about it a little more, i solved the problem and the solution is this function login($username,$password){ $xml = simplexml_load_file("data/xml/users.xml") or die ("Fatal Error opening file"); $super = $xml->xpath("user/username[text()='$username']/../password[text()='$password']/../type[text()='super']"); $normal = $xml->xpath("user/username[text()='$username']/../password[text()='$password']/../type[text()='normal']"); if($super[0] !=null || $normal[0] !=null){ if($super[0] != null){ $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['validAdminUser'] = true; }else if($normal[0] != null){ $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['validUser'] = true; } }else{ $error = "Invalid Username or Password"; } } Link to comment https://forums.phpfreaks.com/topic/135741-making-new-session-variables/#findComment-707289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.