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
  • 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 39
paypal ipn url 5 60
Display images from mysql blob type (Not working) 9 31
How can I make this form submit to itself? 10 28
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

825 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