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

  • SEARCH
  • Home
  • 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 8956915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:52:17+00:00 2026-06-15T14:52:17+00:00

I have a user login system for a website set up with PHP and

  • 0

I have a user login system for a website set up with PHP and MySQL. My question was whether or not I could modify what I have now, to create a “permissions” system. In other words, only display certain controls for users and different ones for administrators. In my mysql table I have columns 'id', 'username', 'password', and an ENUM ‘permissions’ with ‘a’,’b’. ‘a’ is default (not admin). Below I will show you what I have tried.

This file is “checklogin.php” (for the sake of saving space I will not add all of the code)

//First I include variables to connect to the database & connect
//Then I define username and password as $_POST from a form on an earlier page
$user=a;
$admin=b;
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and permissions='$user'";
$sqladmin="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and permissions='$admin'";
$result=mysql_query($sql);
$resultadmin=mysql_query($sqladmin);

$count=mysql_num_rows($result);
$countadmin=mysql_num_rows($resultadmin);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
 // Register $myusername, $mypassword and redirect to file "login_success.php"
 session_register("myusername");
 session_register("mypassword"); 
 session_register("user"); 
 header("location:login_success.php");
}
else {
  if($countadmin==1){
   session_register("myusername");
   session_register("mypassword"); 
   session_register("admin"); 
   header("location:login_success.php");
  }
  else {
    if($count==0) {
      if($countadmin==0) {
       echo "Wrong Username or Password";
      }
    }
  }
}

So in this file I am checking how many rows of the table match the user input and whether or not it is admin, and if there is one, then I register a session with username, password, and permissions.

Next, I have the file “login_success.php“

<?php
session_start();
if(!session_is_registered(myusername)){
 header("location:main_login.php");
}
else {
}
?>
<html>
<body>
Login Successful

<?php
if(session_is_registered(admin)){
echo "Welcome Admin!";
}
else {
echo "Not admin...";
}
?>

The code above simply checks if the session is registered and if not, sends you back to the login form. Below that is a section of code that checks if the user is an admin.
The login part of this works I just can’t work out the permissions.

So finally, I guess my question is why does this not work? It seems logically correct. Sorry for the lengthy post. Thanks for any help.

  • 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-15T14:52:19+00:00Added an answer on June 15, 2026 at 2:52 pm

    I would suggest you the logic as follows: if a user has “a” in one of his columns, then you treat him differently. That means that still one only row is coming up for every user. One only session. Same data strusture. Same session. But basing on what is the value of, say, column “permissions” you open him more “doors” in your application. Where everything you gonna have to do is to check if the “permission” of his session is set to “a” or whatever identifies him as admin.

    Hope this helps.
    maxim

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

Sidebar

Related Questions

I have created a website that allow user use facebook login system to regist
I have been comissioned to make a website complete with a user login system
I already have an advanced user login/register system on my website ( colemansystems.psm2.co.uk ).
On my website I have a user login system, when they login they are
I have a web-based system built with user login data based on session variables.
I have detailed stats on user access to my system detailing login and logout
I am using mysql and have a table (Log_Table) storing user login dates, a
I have a CakePHP website with its own login system. In the same server
I have an existing, non-framework-based PHP/MySQL website. It has a simple security model, with
I'm trying to write a User Login System for my website. I'm running WAMP

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.