php_newB Posted November 15, 2006 Share Posted November 15, 2006 Hey thereThis is my first post so I hope I can get some help from here. I want to have a login page where both users and admin can log in. so admin should be redirected to "admin area" and users should be redirected to "members area". In my loginaction file I am trying to establish to different sessions based on different roles but I haven't managed to get this working. Anyway I put my code here I appreciate if anyone can have a look. Here is loginaction[code]<?php include 'dbconfig.php';// Main ---------- session_start(); // Get the data collected from the user $appUsername =$_POST["userid"]; $appPassword =md5($_POST["password"]); $result = mysql_query("SELECT * FROM users WHERE username = '$appUsername' AND password = '$appPassword' ") or die ("Error in query: $query. ".mysql_error()); while ($row = mysql_fetch_array($result)) { $role = $row['role']; } // see if any rows were returned if (mysql_num_rows($result) > 0) { if ( $role == 'ADMIN' ) { // Relocate to the logged-in page $_SESSION["authenticatedAdmin"] = $appUsername; header("Location: admin.php"); } if ( $role == 'MEMBER' ) { $_SESSION["authenticatedUser"] = $appUsername; // Relocate to the logged-in page header("Location: members.php"); } } //End First if if (empty($appUsername) or empty($appPassword)) { $_SESSION["message"] = "Please enter Username and Password " ; header("Location: login.php"); } else { $_SESSION["message"] = " User $appUsername does not exist or wrong password " ; header("Location: login.php"); } mysql_free_result($result); mysql_close($conn);?>[/code] and here is login(this is without my HTML) [code]<?php //Start - so we can use session variables session_start(); if (isset($_SESSION["authenticatedUser"])) { header("Location: members.php"); } if (isset($_SESSION["authenticatedAdmin"])) { header("Location: admin.php"); } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/27392-role-based-authentication-problem/ Share on other sites More sharing options...
JasonLewis Posted November 16, 2006 Share Posted November 16, 2006 so whats wrong with it. because you didn't state any errors in your first post. oh and just so you know, if your selecting a specific user you dont have to do a while command to get the data, just go $row = mysql_fetch_array($result); Link to comment https://forums.phpfreaks.com/topic/27392-role-based-authentication-problem/#findComment-125421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.