Jump to content

[SOLVED] Multi level log in


gavin1512

Recommended Posts

Good Day,

 

I am currently working on an internal order system for my Dissertation project and having problem locating some code for a multi level log in system, my system has four levels of log in and each will require a different home page, any help would be much appreciated.

 

Thank You  ;D

Gavin

Link to comment
Share on other sites

try somthing like this if you already have a levels column in your table for user level

 

switch ($row['level']) {
case 0:
    header('level0.php');
    break;
case 1:
    header('level1.php');
    break;
case 2:
    header('level2.php');
    break;
}

 

Hope that this is of use to you.

 

Regards

Liam

Link to comment
Share on other sites

Thanks Liam,

 

That is what I need, not being to great with PHP and mySQL before I spend ages playing about can I just check something...

does this line "switch ($row['level']) {" refer to the row in the database? in my case this is access. In mySQL access is either user, manager, approver or administrator, how do I apply these scenarios in to the case?

 

thank you for your help hope you are having a good day.

Link to comment
Share on other sites

<?php

switch ($row['access']) {
  case 'manager':
    header('manager.php');
    break;
  case 'approver':
    header('approver.php');
    break;
  case 'admin':
    header('admin.php');
    break;
}

?>

Link to comment
Share on other sites

still have an issue due to my inexperience with PHP and not having used it for 2 years, I tired embedding the case statement in my If statement for checking username and password, below is my code:

 

<?php

session_start();

require "connect.php";

$username = $_GET['username'];

$password = $_GET['password'];

$query = "select * from employee where username = '".$username."' and password = '".$password."'";

$result = mysql_query($query, $connection)

or die ("Unable to perform query<br>$query");

$row= mysql_fetch_array($result);

if ($row != null)

{

$_SESSION['username'] = $row['username'];

 

switch ($row['access']) {

case 'user':

    header('user home.php');

    break;

 

  case 'manager':

    header('manager home.php');

    break;

 

    case 'approver':

    header('approver home.php');

    break;

 

    case 'admin':

    header('admin home.php');

    break;

}

exit();

}

else

{

$message = "Invalid username or password, please try again";

header("Location: home.php? message=$message");

exit();

}

?>

 

If some one could set me straight on where best to put it I will be very relieved lol

Link to comment
Share on other sites

in my SQL database the field is stored as admin, originally before the case break statement it would just point at user home.php, but now i have tried all four levels of log in and no page loads and no error message is displayed. The page it tries to load is http://localhost/logincheck.php?username=abowell&password=liverpool&submit=Login and not the actual page relevant to the level of log in.

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.