Jump to content

Session object not working?


ttocskcaj

Recommended Posts

I have two test files.

First file: (test.php)

<?php
session_start();
function __autoload($class) {
include "../libs/$class.php";
}
$_SESSION = new session("ttocskcaj",84824526893564);
echo "Welcome ".$_SESSION->getUsername();
echo '<p><a href="test2.php">Test 2</a></p>';

Second File  (test2.php)

<?php
session_start();
function __autoload($class) {
include "../libs/$class.php";
}
print_r($_SESSION);
echo "Welcome ".$_SESSION->getUsername();

echo '<p><a href="test.php">Test 1</a></p>';

But the second file just returns this;

Array ( )
Fatal error: Call to a member function getUsername() on a non-object in C:\xampp\htdocs\main\zend\TFFW\public\test2.php on line 4

 

Here's the session class https://github.com/ttocskcaj/The-Forum-Framework/blob/master/libs/session.php

Is it even possible to save objects in a session? If so, what's going wrong?

Link to comment
Share on other sites

The class definition must be included before the session_start() statement AND $_SESSION is the actual session variable array. You would need to use a specifically named session variable, something like -

 

$_SESSION['user'] = new session("ttocskcaj",84824526893564);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.