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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:32:45+00:00 2026-06-01T07:32:45+00:00

I am trying to create a sessions and entry to pages based on a

  • 0

I am trying to create a sessions and entry to pages based on a person’s “role” in the database. I thought I nailed the logic and I created the code. It worked. Problem is, it works for everyone. I wanted some help to point out why my code is logically incorrect when to me it’s on point. Any help will be greatly appreciated. Here is my code. It seems to let in anyone who’s role is not ‘Admin’ and I can pin point why:

function auth($email, $pass){
        global $result;

        while ($row = mysql_fetch_array($result)) {
            if($email == $row["email"] && $pass == $row["password"])
            {
                return true;
            }
        }
        return false;
    }

    function test($email, $pass){
        $test1 = auth($email, $pass); <--above
        if ($test1) {
           get_role($email); <-- below (This is the one where I'm puzzled)
        $_SESSION['email'] = true;
            header('location:menupage.php');
            exit;      
        }
        else{
            echo "Please enter correct username and password or <a href='register.php'>Register</a>";}
    }

    function get_role($email){
    global $connection;
    $sql="SELECT * FROM exam WHERE email= '$email'";
    $result = mysql_query($sql, $connection);
    confirm_query($result);
    while ($row = mysql_fetch_array($result)) {
        if ($row["role"] == 'Admin'){
                $_SESSION['role'] = true;
            }
            else
            $_SESSION['role'] = false;
    }


    }

and this is the header for the administrative page that has the session

<?php
session_start();
if(!isset($_SESSION['role']))
{   $_SESSION['msg'] = 'you are not logggedd in';
    header('location: menupage.php');
    exit;
}
?>
  • 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-01T07:32:46+00:00Added an answer on June 1, 2026 at 7:32 am

    $_SESSION['role'] = false is still a variable that is set. so !isset($_SESSION['role']) will not evaluate as you expect. Use something like:

    Admin page:

    if($_SESSION['role'] === false){ ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a more secure PHP sessions login script. Unfortunately for
I'm trying to create a Tkinter GUI that saves all entry box values into
I'm trying to create different checkout sessions for the logged in customer at a
A little background: I am trying to create a lightweight cookieless database-backed user session
So I'm trying to get a simple session based login working, and my sessions
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation

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.