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

Archived

This topic is now archived and is closed to further replies.

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