× Didn't find what you were looking for? Ask a question
Top Posters
Since Sunday
a
5
1
New Topic  
JuliaH JuliaH
wrote...
Posts: 61
Rep: 0 0
12 years ago
I want to program a website that has two different kind of users: one is admin and the other one is called user.

The admin has certain rights whereas the user does not have all the right an admin have.

How do I use PHP to store what type of user is logged in and can be used on every other pages? In my database, admin has an id of 1, and user has an id of 2.
Read 478 times
2 Replies

Related Topics

Replies
wrote...
12 years ago
Interesting... You could try making a table with a session list in it, and store a cookie with an id or something. For every page a user visits, a new entry is made in the session table for that id. Then it's just a simple matter of writing a function that outputs that session table.
wrote...
12 years ago
You're going to want to use $_SESSION.  When the user logs in run a mysql query to grab the type of user.  After you have the variable just use something like this to store it:session_start();
$_SESSION['uid'] = $uid;
$_SESSION['type'] = $type;
session_write_close();
?>

Then whenever you want to check what kind of user is logged in you can just use:

session_start();
$type = $_SESSION['type'];
session_write_close();
?>

Just make sure to use it at the top of the page.  If you try to run session_start() after anything has been output to the web page it won't work.  Just email me if you need any help with this.
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  667 People Browsing
Related Images
  
 711
  
 1207
  
 370
Your Opinion
Which industry do you think artificial intelligence (AI) will impact the most?
Votes: 798