PHP multiple user level login page -
I'm new to PHP and I'm stuck with it, so any help is appreciated.
I have 4 user_ levels in my DB:
ID name 1 admin 2 member 3 cashier 4 unregistered user
The problem is, when anyone If the user logs in, then it redirects to the page profile php. And I need other permissions, search results etc. for every user. How can I do this?
login.php
& lt ;; Doctype html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Login & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;? Include php 'connect.php'; ? & Gt; & Lt ;? Php included 'functions.php'; ? & Gt; & Lt ;? Php includes 'title_bar.php'; ? & Gt; & Lt; H2 & gt; Login: & lt; / H2 & gt; & Lt; Form method = 'POST' & gt; & Lt ;? Php if (isset ($ _ POST ['submit'])) {$ username = $ _ POST ['username']; $ Password = $ _ post ['password']; If (empty ($ username) or empty ($ password)) echo "you missed something!"; } And {$ check_login = mysql_query ("select ID, type user WHERE user name = '$ user name' and password = '$ password'"); If (mysql_num_rows ($ check_login)! = 0) {$ run = mysql_fetch_array ($ check_login); $ User_id = $ run ['id']; $ Type = $ run ['type']; If ($ type == 'd') {resonant "& lt; p> the account is not active! "; } And {$ _SESSION ['user_id'] = $ user_id; Header ("location: profile.fp"); }} And {echo " incorrect information! "; }}}? & Gt; & Lt; Br / & gt; Username: & lt; Br / & gt; & Lt; Input type = 'text' name = 'username' & gt; & Lt; Br / & gt; & Lt; Br / & gt; Near: & lt; Br / & gt; & Lt; Input type = 'password' name = 'password' & gt; & Lt; Br / & gt; & Lt; Br> & Lt; Input type = 'submit' name = 'submit' value = 'login' & gt; & Lt; Br / & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;
session_start.php
& lt ;? Php session_start (); Function log () (if isset ($ _ session ['user_id']) & amp; empty! ($ _ Session ['user_id'])) {back true;} other {return false;}}? & Gt Get your user's record from the user's table, set permisson in a $ _SESSION variable, and redirect them to the appropriate page, depending on their permission. Of course, you must specify the table name, form field Need to change name, column name, method method, etc. ...
Edit: Because you Your code is added, it is an updated version based on your code:
if ($ type == 'd') {resonance " Account is not active! & Lt; / p & gt; ";} and {$ _SESSION ['user_id'] = $ user_id; $ _SESSION ['type'] = $ run ['type']; switch ($ run [" type "]) {Case 1: // admin header ("location: admin.fp"); die (); breakage; case 2: // member header ("location: member.php"); die (); breakage; case 3: // Cashier Header ("Location: Cashier.fp"); Dying (); Breakage; Case 4: Header ("S Venue: unregistered. Php "); (die); // unregistered user break; }}
Comments
Post a Comment