Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-23
4
Medium Priority
?
367 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
[X]
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
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

671 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