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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:34:54+00:00 2026-05-27T10:34:54+00:00

Trying to save the $_SESSION[‘uID’] within the session to use for functions like pulling

  • 0

Trying to save the $_SESSION['uID'] within the session to use for functions like pulling up recent orders, etc.

I have a few files:

** login/index.php ** – This is the page users visit to login (aka enter in user/pass), which includes a bunch of html markup and this php:

<?php
session_start();

require_once('../inc/db/dbc.php');
?>

check_buyer.php – that is called when a user visits login/index.php and enters in credentials. This file, upon entering in correct credentials will store $_SESSION variables using the function: validateUser{}

  <?php
session_start(); #recall session from index.php where user logged include()

function isLoggedIn()
{
    if(isset($_SESSION['valid']) && $_SESSION['valid'])
        header( 'Location: buyer/' ); # return true if sessions are made and login creds are valid
    echo "Invalid Username and/or Password";  
    return true;
}

require_once('../inc/db/dbc.php');

$connect = mysql_connect($h, $u, $p) or die ("Can't Connect to Database.");
mysql_select_db($db);

$LoginUserName = $_POST['userName'];
$LoginPassword = mysql_real_escape_string($_POST['userPass']);
//connect to the database here
$LoginUserName = mysql_real_escape_string($LoginUserName);
$query = "SELECT uID, uUPass, dynamSalt, uUserType FROM User WHERE uUName = '$LoginUserName';";

$result = mysql_query($query);
if(mysql_num_rows($result) < 1) //no such USER exists
{
    echo "Invalid Username and/or Password";
}
$ifUserExists = mysql_fetch_array($result, MYSQL_ASSOC);

function validateUser() {
    $_SESSION['valid'] = 1;
    $_SESSION['uID'];
    $_SESSION['uUserType'] = 1; // 1 for buyer - 2 for merchant
}

$dynamSalt = $ifUserExists['dynamSalt'];  #get value of dynamSalt in query above
$SaltyPass = hash('sha512',$dynamSalt.$LoginPassword); #recreate originally created dynamic, unique pass

if($SaltyPass != $ifUserExists['uUPass']) # incorrect PASS
{
    echo "Invalid Username and/or Password";
}

else {
validateUser();
}
// If User *has not* logged in yet, keep on /login
if(!isLoggedIn())
{
    header('Location: index.php');
    die();
}
?>

If all login details are fine, it redirects to /login/buyer/index.php

 <?php
session_start();
if($_SESSION['uUserType'] != 1) // error
{ 

    die("
    <div class='container_infinity'>
        <div class='container_full' style='position:static;'>
        <img src='img/error/noAccess.png' style='float:left;' /> <br />
        <h2>403 Error: You may not view this page. Access denied.</h2>
        </div>
    </div>
    ");
}

function isLoggedIn()
{
    return ($_SESSION['valid'] == 1 && $_SESSION['uUserType'] == 1);
}

//if the user has not logged in
if(!isLoggedIn())
{
    header('Location: ../index.php');
    die();
}
?>

<?php 
    if($_SESSION['valid'] == 1 && $_SESSION['uUserType'] == 1){
        #echo "<a href='../logout.php'>Logout</a>";
        echo 'buyerid: '.$_SESSION['uID'];
        require_once('buyer_profile.php');
    }
    else{
        echo "<a href='../index.php'>Login</a>";
    }
?>

When it reaches the /login/buyer/index.php, right now I’m JUST trying to output the user’s userid aka $buyerUserID; as created back in the file check_buyer.php . Why isn’t this getting any value? All pages have the session_start(); at top too

  • 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-05-27T10:34:54+00:00Added an answer on May 27, 2026 at 10:34 am

    You need to set $_SESSION['uID'] = $ifUserExists['uID']; in your login process.

    EDIT:

    Then in your buyer php script you need to output $_SESSION['uID'] instead of $buyerUserId

    <?php
    session_start(); #recall session from index.php where user logged include()
    
    function isLoggedIn()
    {
        if(isset($_SESSION['valid']) && $_SESSION['valid'])
            header( 'Location: buyer/' ); # return true if sessions are made and login creds are valid
        echo "Invalid Username and/or Password";  
        return true;
    }
    
    require_once('../inc/db/dbc.php');
    
    $connect = mysql_connect($h, $u, $p) or die ("Can't Connect to Database.");
    mysql_select_db($db);
    
    $LoginUserName = $_POST['userName'];
    $LoginPassword = mysql_real_escape_string($_POST['userPass']);
    //connect to the database here
    $LoginUserName = mysql_real_escape_string($LoginUserName);
    $query = "SELECT uID, uUPass, dynamSalt, uUserType FROM User WHERE uUName = '$LoginUserName';";
    
    $result = mysql_query($query);
    if(mysql_num_rows($result) < 1) //no such USER exists
    {
        echo "Invalid Username and/or Password";
    }
    $ifUserExists = mysql_fetch_array($result, MYSQL_ASSOC);
    
    function validateUser() {
        $_SESSION['valid'] = 1;
        $_SESSION['uID'] = (isset($ifUserExists['uID'])) ? $ifUserExists['uID'] : null;
        $_SESSION['uUserType'] = 1; // 1 for buyer - 2 for merchant
    }
    
    $dynamSalt = $ifUserExists['dynamSalt'];  #get value of dynamSalt in query above
    $SaltyPass = hash('sha512',$dynamSalt.$LoginPassword); #recreate originally created dynamic, unique pass
    
    if($SaltyPass != $ifUserExists['uUPass']) # incorrect PASS
    {
        echo "Invalid Username and/or Password";
    }
    
    else {
    validateUser();
    }
    // If User *has not* logged in yet, keep on /login
    if(!isLoggedIn())
    {
        header('Location: index.php');
        die();
    }
    ?>
    
    
    <?php
    session_start();
    if($_SESSION['uUserType']!=1) // error
    { 
    
        die("
        <div class='container_infinity'>
            <div class='container_full' style='position:static;'>
            <img src='img/error/noAccess.png' style='float:left;' /> <br />
            <h2>403 Error: You may not view this page. Access denied.</h2>
            </div>
        </div>
        ");
    }
    
    function isLoggedIn()
    {
        return ($_SESSION['valid'] = 1 && $_SESSION['uUserType'] = 1);
    }
    
    //if the user has not logged in
    if(!isLoggedIn())
    {
        header('Location: ../index.php');
        die();
    }
    ?>
    
    <?php 
        if($_SESSION['valid'] == 1 && $_SESSION['uUserType'] == 1){
            #echo "<a href='../logout.php'>Logout</a>";
            echo 'buyerid: '.$_SESSION['uID'];
            require_once('buyer_profile.php');
        }
        else{
            echo "<a href='../index.php'>Login</a>";
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i'm trying to save the values of a SimpleXMLElement to a $_SESSION but
I am trying to save session data to the users local ApplicationData folder, but
I am trying to save my _POST array to a _SESSION array so that
I'm trying to use memcache to handle session in PHP. I still want to
I am trying to save the OrderedDictionary into the session and reload it. basically,
Im trying to save a bitmap jpg format with a specified encoding quality. However
I am trying to save data to a database on a button push, but
I'm trying to save some XML-Data in my UserSettings (Properties.Settings.Default.UserSettings) in a .NET Winforms
I'm trying to save a PDF file to SQL Server and I already have
We are trying to save the state of the application on exit and restore

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.