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 9016923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:07:50+00:00 2026-06-16T04:07:50+00:00

I want to show different content if a user is admin(2), or noarmal user(1).

  • 0

I want to show different content if a user is admin(2), or noarmal user(1). Login works fine, but i don’t know hot to check if a user have ‘usertype’ 1 or 2? I want to use PHP $_SESSION.

This is my login form:

<!-- Log in -->
<form method="post" action="authentication.php">
  <input type="text" name="userid" placeholder="E-mail" required/>
  <input type="password" name="password" placeholder="Password" required/><br>
  <button type="submit" name="submit" class="btn">Log in</button>
</form>

This is my authentication.php:

session_start();
if(isset($_POST['userid']) && isset($_POST['password'])){
$userid     = $_POST['userid'];
$password   = $_POST['password'];

$dbc        = mysqli_connect('localhost', 'root', '', 'news');
if(!$dbc){
echo "Cannot connect to database";
exit;
}

$query      = "SELECT * FROM users_tbl WHERE email = '$userid' AND password = sha1('$password')";
$result     = $dbc->query($query);
if($result->num_rows)
{
$_SESSION['valid_user'] = $userid;
}
$dbc->close();
}
if(isset($_SESSION['valid_user'])){
header("location:prefs.php");
}else{
header("location:login.php");
echo 'Error';
}

This is what i have tried:

    <?php 

    mysql_connect('localhost', 'root', '');
    mysql_select_db('news');

    $sql = "SELECT users_tbl.usertype FROM users_tbl";
    $result = mysql_query($sql); 
    $user = mysql_fetch_array($result);
    $_SESSION['user'] = $user['user']; 
    $_SESSION['usertype'] = $user['usertype'];        

    if($_SESSION['user']['usertype'] == 2)
    {?>
    <h1>Only admin stuff</h1>

    <$? }//Endif user is admin(2) ?>

Maybe instead of doing the query for everytime to check if a user is admin, i could save a $_SESSION[‘usertype’], and then use this to check if a user is 2, for admin, maybe when a user is loggin in? But i do not know how to do this. I’m quite new at this.

  • 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-16T04:07:52+00:00Added an answer on June 16, 2026 at 4:07 am

    try this

       if($_SESSION['usertype'] == 2)
    {
       //do stuff here 
    }
     if ($_SESSION['usertype']) == 1)
    
     {
     //do stuff here 
     }
    

    edit :
    if you dont want write so many stuff and you want just include admin stuff inside this one of users just do this

      if ($_SESSION['usertype']) == 1 or $_SESSION['usertype']) == 2)
    
       {
                  //do stuff here for them both admin and users
             if($_SESSION['usertype'] == 2 ) 
                                       {
                                      //do extra stuff here for only admin 
                                        }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show array objects at the same time in different 10 labels.
In my Rails controller I want to branch to a different controller's action, show
I want to show a border type look for an element but without using
I want to show my groupview with 2 lines to down direction, but only
I want to show the content of a nested table using a cursor. I've
I want to show some media of different categories (e.g. mostViewed, starred) in a
I want to show my first-time users different functions of my web-app. To do
I'd like to show a different fragment in a TabHost, for every tab. But
I want to show two different activites of a single application into a single
I want show an information page after success db opartions. And after the info

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.