how to load another user session. What code should I add

Posted on 2014-03-23
Last Modified: 2014-03-23
<?php # - Script 9.3
// This page needs to do the setup and configuration required by every other page.

// Autoload classes from "classes" directory:
function class_loader($class) {
    require('classes/' . $class . '.php');

// Start the session:

// Check for a user in the session:
$user = (isset($_SESSION['user'])) ? $_SESSION['user'] : null;

// Create the database connection as a PDO object:
try { 

    // Create the object:
    $pdo = new PDO('mysql:dbname=cms;host=localhost', 'root', '');

} catch (PDOException $e) { // Report the error!
    $pageTitle = 'Error!';

Open in new window

<?php # index.php - Script 9.7

// Need the utilities file:

// Include the header:
$pageTitle = 'Welcome to the Site!';

// Fetch the three most recent pages:
try {
    $q = 'SELECT id, title, content, DATE_FORMAT(dateAdded, "%e %M %Y") AS dateAdded FROM pages ORDER BY dateAdded DESC LIMIT 3'; 
    $r = $pdo->query($q);
    // Check that rows were returned:
    if ($r && $r->rowCount() > 0) {

        // Set the fetch mode:
        $r->setFetchMode(PDO::FETCH_CLASS, 'Page');

        // Records will be fetched in the view:

    } else { // Problem!
        throw new Exception('No content is available to be viewed at this time.');
} catch (Exception $e) { // Catch generic Exceptions.

// Include the footer:

Open in new window

cookie is loaded quickly

session is null, $user is null

how can I have user have a value
Question by:rgb192
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 58

Expert Comment

ID: 39948748
What do you mean
how to load another user session
I don't see where you are setting the session prior to checking it exists

Author Comment

ID: 39948760
line 13,14

// Check for a user in the session:
$user = (isset($_SESSION['user'])) ? $_SESSION['user'] : null;

what happens if there is/(is not) a user in the session
how can I simulate both  
I think no user (user=null) is what happens currently
so how can I simulate user=something
LVL 58

Accepted Solution

Gary earned 500 total points
ID: 39948763
Just set it to something before that line


Author Closing Comment

ID: 39948817
solution works. Thanks

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Introduction This article is intended for those who are new to PHP error handling (  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question