Jump to content

detect user_type login help


fifin04

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.