Solved

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

Posted on 2014-03-23
4
356 Views
Last Modified: 2014-03-23
utilities.inc.php
<?php # utilities.inc.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');
}
spl_autoload_register('class_loader');

// Start the session:
session_start();

// 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!';
    include('includes/header.inc.php');
    include('views/error.html');
    include('includes/footer.inc.php');
    exit();
    
}

Open in new window


index.php
<?php # index.php - Script 9.7

// Need the utilities file:
require('includes/utilities.inc.php');

// Include the header:
$pageTitle = 'Welcome to the Site!';
include('includes/header.inc.php');

// 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:
        include('views/index.html');

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

// Include the footer:
include('includes/footer.inc.php');
?>

Open in new window




cookie is loaded quickly

session is null, $user is null

how can I have user have a value
0
Comment
Question by:rgb192
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
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
0
 

Author Comment

by:rgb192
ID: 39948760
line 13,14 utilties.inc.php

// 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
0
 
LVL 58

Accepted Solution

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

$_SESSION['user']="user1";
0
 

Author Closing Comment

by:rgb192
ID: 39948817
solution works. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now