fifin04 Posted March 23, 2007 Share Posted March 23, 2007 Hi nice people out there... Okay currently I'm working on my log system for my office use...so my purpose is just wanna seek advise/guide from php guru's here...the best/proper way to code this....Okay my problem is here...how to differentiate user level after the user success logging into the system....because what I'm working is now..I have 3 different page depends on user type after successing login...let's say I have this type of record in my dtbase... id | username | password | user_type | ____________________________________ 0 | user1 | pwd | director | 1 | user2 | pwd2 | sa | 2 | user3 | pwd3 | programmer| so the scenario is if the director login it'll redirect to "directorindex.php" page -and if sa succesing login into system it'll redirect to "saindex.php" page and so on... so I really need help on how to detect user_type after the login process because I want to redirect to the correct page....hope will get some shed on light on it... thanks in advanced Link to comment https://forums.phpfreaks.com/topic/43921-detect-user_type-login-help/ Share on other sites More sharing options...
ridiculous Posted March 23, 2007 Share Posted March 23, 2007 Personally, and this is shooting straight from the hip on an empty stomach after just gettin out of jail, I would just 1. add a column into your mysql db for user_type, 2. query the result upon login, and then 3. use f_write to write that info to the the log. Then I would 4. probably go get some Chinese food. Link to comment https://forums.phpfreaks.com/topic/43921-detect-user_type-login-help/#findComment-213247 Share on other sites More sharing options...
rajeshrhino Posted March 23, 2007 Share Posted March 23, 2007 After the login is successful, you would be knowing the 'id' of the logged in user.Just use the below code after checking the login $user_result = mysql_fetch_assoc(mysql_query("select user_type from users where id='$userid'")); // here $userid is the 'id' of the successfully logged in user. if($user_result['user_type']=='director') header("Location:directorindex.php"); else if($user_result['user_type']=='sa') header("Location:saindex.php"); else if($user_result['user_type']=='programmer') header("Location:programmerindex.php"); hope this would solve your problem. Link to comment https://forums.phpfreaks.com/topic/43921-detect-user_type-login-help/#findComment-213249 Share on other sites More sharing options...
ridiculous Posted March 23, 2007 Share Posted March 23, 2007 rajes, work with me here babe. Why the headers? For why dog? Link to comment https://forums.phpfreaks.com/topic/43921-detect-user_type-login-help/#findComment-213250 Share on other sites More sharing options...
wilorichie Posted March 23, 2007 Share Posted March 23, 2007 It's best to use 2 tables here 1. User Types You asked about the best way to code it, so I would change your table structure to below. Either way, your table columns will still work. id:1 type: ceo id: 2 type: programmer etc... Then, in your users table, you have id: 1 user: username pass: password user_auth: 1 It's best to use digits when possible. Anyways, when you login, you would use a similar query as such: $query = "select * from userstable WHERE username = '$user' AND password = '$pass'"; now, you have a specific user logged in. You can use the below to get more information about this user while($row = mysql_fetch_assoc($query)){ $auth = $row['user_auth']; } $auth will display a number depending on their auth. You can now use if states to redirect etc... Link to comment https://forums.phpfreaks.com/topic/43921-detect-user_type-login-help/#findComment-213251 Share on other sites More sharing options...
ridiculous Posted March 23, 2007 Share Posted March 23, 2007 Would there be an speed loss or gain in a situation where you had...say 1,000 people per minute logging in by using one or two tables? Link to comment https://forums.phpfreaks.com/topic/43921-detect-user_type-login-help/#findComment-213254 Share on other sites More sharing options...
wilorichie Posted March 23, 2007 Share Posted March 23, 2007 You would not use both tables when logging in. The purpose for the first table is merely for creating new 'positions' by an admin. When a new user is made, you would extra the position number from table 1 and put in that number in table 2. Thats it. It's also more friendly when coding and when naming your new positions. Extra time logging in: 0 Link to comment https://forums.phpfreaks.com/topic/43921-detect-user_type-login-help/#findComment-213258 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.