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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:17:22+00:00 2026-05-11T01:17:22+00:00

I’m using PHP 4.3.9, Apache/2.0.52 I’m trying to get a login system working that

  • 0

I’m using PHP 4.3.9, Apache/2.0.52

I’m trying to get a login system working that registers DB values in a session where they’re available once logged in. I’m losing the session variables once I’m redirected.

I’m using the following code to print the session ID/values on my login form page and the redirected page:

echo '<font color='red'>session id:</font> ' . session_id() . '<br>'; echo '<font color='red'>session first name:</font> ' . $_SESSION['first_name'] . '<br>'; echo '<font color='red'>session user id:</font> ' . $_SESSION['user_id'] . '<br>'; echo '<font color='red'>session user level:</font> ' . $_SESSION['user_level'] . '<br><br>'; 

This is what’s printed in my browser from my login page (I just comment out the header redirect to the logged in page). This is the correct info coming from my DB as well, so all is fine at this point.

session id: 1ce7ca8e7102b6fa4cf5b61722aecfbc session first name: elvis session user id: 2 session user level: 1 

This is what’s printed on my redirected/logged in page (when I uncomment the header/redirect). Session ID is the same, but I get no values for the individual session variables.

session id: 1ce7ca8e7102b6fa4cf5b61722aecfbc session first name: session user id: session user level: 

I get the following errors:

Undefined index: first_name
Undefined index: user_id
Undefined index: user_level

I have a global header.php file which my loggedIN.php does NOT call, though loggedOUT.php does – to toast the session):

header.php

<?php ob_start(); session_start();  //if NOT on loggedout.php, check for cookie. if exists, they haven't explicity logged out so take user to loggedin.php if (!strpos($_SERVER['PHP_SELF'], 'loggedout.php')) {     /*if (isset($_COOKIE['access'])) {         header('Location: www.mydomain.com/loggedin.php');     }*/ } else {     //if on loggedout.php delete cookie     //setcookie('access', '', time()-3600);      //destroy session     $_SESSION = array();     session_destroy();     setcookie(session_name(), '', time()-3600); }  //defines constants and sets up custom error handler require_once('config.php');  ?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>  some page layout stuff  Login portion is eventually called via include  footer stuff 

My loggedIN.php does nothing but start the session

<?php session_start(); ?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> 

The logic of my login script, the key part being I’m fetching the DB results right into $_SESSION (about half way down):

if (isset($_POST['login'])) {         //access db         require_once(MYSQL);          //initialize an errors array for non-filled out form fields         $errors = array();          //setup $_POST aliases, clean for db and trim any whitespace         $email  = mysql_real_escape_string(trim($_POST['email']), $dbc);         $pass   = mysql_real_escape_string(trim($_POST['pass']), $dbc);          if (empty($email)) {             $errors[] = 'Please enter your e-mail address.';         }          if (empty($pass)) {             $errors[] = 'Please enter your password.';         }          //if all fields filled out and everything is OK         if (empty($errors)) {             //check db for a match             $query = 'SELECT user_id, first_name, user_level                      FROM the rest of my sql here, blah blah blah';              $result = @mysql_query($query, $dbc)                  OR trigger_error('Query: $query\n<br />MySQL Error: ' . mysql_error($dbc));              if (@mysql_num_rows($result) == 1) { //a match was made, OK to login                  //register the retrieved values into $_SESSION                 $_SESSION = mysql_fetch_array($result);                 mysql_free_result($result);                 mysql_close($dbc);                 /*                               setcookie('access'); //if 'remember me' not checked, session cookie, expires when browser closes                                      //in FF you must close the tab before quitting/relaunching, otherwise cookie persists                  //'remember me' checked?                 if(isset($_POST['remember'])){ //expire in 1 hour (3600 = 60 seconds * 60 minutes)                     setcookie('access', md5(uniqid(rand())), time()+60); //EXPIRES IN ONE MINUTE FOR TESTING                 }                 */  echo '<font color='red'>cookie:</font> ' . print_r($_COOKIE) . '<br><br>'; echo '<font color='red'>session id:</font> ' . session_id() . '<br>'; echo '<font color='red'>session first name:</font> ' . $_SESSION['first_name'] . '<br>'; echo '<font color='red'>session user id:</font> ' . $_SESSION['user_id'] . '<br>'; echo '<font color='red'>session user level:</font> ' . $_SESSION['user_level'] . '<br><br>';                  ob_end_clean();                 session_write_close();                  $url = BASE_URL . 'loggedin_test2.php';                 header('Location: $url');                 exit();             } else {             //wrong username/password combo             echo '<div id='errors'><span>Either the e-mail address or password entered is incorrect or you have not activated your account. Please try again.</span></div>';             }              //clear $_POST so the form isn't sticky             $_POST = array();         } else {          //report the errors         echo '<div id='errors'><span>The following error(s) occurred:</span>';              echo '<ul>';             foreach($errors as $error) {                 echo '<li>$error</li>';             }             echo '</ul></div>';         }      } // end isset($_POST['login']) 

if I comment out the header redirect on the login page, I can echo out the $_SESSION variables with the right info from the DB. Once redirected to the login page, however, they’re gone/unset.

Anyone have any ideas? I’ve spent nearly all day on this and can’t say I’m any closer to figuring it out.

BTW, I recently made 2 simple test pages, one started a session, set some variables on it, had a form submit which redirected to a second page which did nothing but read/output the session vars. It all seems to work fine, I’m just having issues with something I’m doing in my main app.

  • 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. 2026-05-11T01:17:22+00:00Added an answer on May 11, 2026 at 1:17 am

    I don’t see a session_start() in your login script. If you aren’t starting the session I don’t think php will save any data you place in the $_SESSION array. Also to be safe I’d explicitly place variables into the $_SESSION array instead of just overwriting the whole thing with $_SESSION = mysql_fetch_array($result);.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There's an Assembly.Load(byte[]) overload that you can use to load… May 11, 2026 at 10:49 am
  • added an answer Jeff's reason for disliking properties is because they look like… May 11, 2026 at 10:49 am
  • added an answer Declaration: No. It doesn't make sense to talk about declaring… May 11, 2026 at 10:49 am

Related Questions

I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I have a web-service that I will be deploying to dev, staging and production.
I'm thinking of starting a wiki, probably on a low cost LAMP hosting account.
I have the following tables in my database that have a many-to-many relationship, which
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I recently printed out Jeff Atwood's Understanding The Hardware blog post and plan on
I find that getting Unicode support in my cross-platform apps a real pain in
I would like to test a string containing a path to a file for
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I'm an Information Architect and JavaScript developer by trade nowadays, but recently I've been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.