Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9072163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:06:22+00:00 2026-06-16T18:06:22+00:00

I have a login script which checks if the authority id is 5 =

  • 0

I have a login script which checks if the authority id is 5 = admin, 6 = employee, or 7 = student.

Please check below:

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT * FROM users WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);

// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){   
// Register $myusername, $mypassword and redirect to file "main.php"
$_SESSION["myusername"] = $myusername;
$_SESSION["mypassword"] = $mypassword;

while($count = mysql_fetch_assoc($result)) {
                              //echo $row['Username'];
                              //echo $row['access_level'];

                              if ($count['AuthorityId']== 5) {
                              //add custom content here for this user access level
                              header("location: adminpage.php");
                              exit();
                              } // end of if

  else if ($count['AuthorityId']== 6 ){
  //add custom content here for this user access level
    header("location: employeepage.php");
     exit();
  } // end of else if
  else{
    header("location: studentpage.php");
     exit();
      }

} // end of while 
}
else if( $myusername == '' || $mypassword == '' ){
echo '<script type="text/javascript">
alert("There are empty fields!");
</script>'; 
}
else {
echo '<script type="text/javascript">
alert("Wrong Username or Password")
</script>';
}
?>

When the user is an admin, he then goes to adminpage.php, but when I would directly put the url for employeepage.php, the user can access it. How can I restrict users from accessing other pages? thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:06:23+00:00Added an answer on June 16, 2026 at 6:06 pm

    Store the authority in another session variable like so:

    if ($count['AuthorityId']== 5) {
        //add custom content here for this user access level
        $_SESSION['authority'] = 5;
        header("location: adminpage.php");
        exit();
    } // end of if
    

    And then use:

    if($_SESSION['authority'] != 5){
        die();
        // Or something more useful like a redirect
    }
    

    On restricted pages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login form which redirects to a php script that then checks
So I have a script which checks the login details.. I have that working,
i am writing web-services for login script. Which i have to keep on HTTPS
I have a login script that when successful, should check to see if the
I am using my admin panel login script where i have created a global.php
In my login script I have put a checkbox that people can check if
I have a script below which the user logs a php form. There is
I have come across the following script which checks whether an element has class
I have a login script which generally works for me, but occasionally goes into
i have a login script in that i check if a certain timeperiod has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.