Please explain it
pass Object through sessions PHP 5
Moderator: General Moderators
pass Object through sessions PHP 5
Is it possible to put Objects in the $_SESSION, $_POST or $_GET in PHP 5? If so, how should I recover them after putting???
Please explain it

Please explain it
feyd | Please use
What should I do? I print_r the $_SESSION in the target page and it contains my object in a strange stucture:
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Yeah
I put an object in the $_SESSION and when I was trying to recover it in the next page I faced this error:Code: Select all
Fatal error: main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Role" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:\Program Files\Apache Group\Apache2\htdocs\epeyk\class\_test2.php on line 10Code: Select all
Array
(
[role] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Role
[id:private] => 1
[title:private] => Administrator
[description:private] => This role has all the permissions
)
)feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]you need to include the class definition for both pages that will use the object.
page1:
page 2:
page1:
Code: Select all
<?php
session_start();
include 'MyClass.php';
$_SESSION['object'] = new MyClass();
?>Code: Select all
<?php
session_start();
include 'MyClass.php';
$_SESSION['object']->myMethod();
?>The class definition must be present before the object is rebuilt from the session data.
Code: Select all
include 'MyClass.php';
session_start();
$_SESSION['object']->myMethod();