Page 1 of 1

Session with objects

Posted: Tue Apr 29, 2003 3:46 pm
by maxi
I had experienced some troubbles setting an object in a variable session. I tried to do:

page1.php
<?php
session_start();

$arbitrer = new COM("Arbitrer.1") or die("I can't create Arbitrer");
$rc = $arbitrer->Logon( $_REQUEST ["name"], $_REQUEST ["password"], $var );
if ( $rc != 0 ){
// function error
...
}
$_SESSION['arbitrer'] = $arbitrer;

header("Location: page2.php");

// That's work right

------------------------------------
page2.php

<?php
session_start();
if ( is_null( $_SESSION['arbitrer'] ) ) {
print "I can't get arbitrer";
}

//Always print the message because abitrer is null


What am i doing wrong??? Anyone has any idea??? I'm driving crazy with this problem!!! :cry:

Posted: Tue Apr 29, 2003 3:50 pm
by maxi
I forgot to say I'm working with Windows NT Workstation 4.0 (SP6) Apache 1.3.7 (I've tried with Apache 2) and PHP 4.3.2 RC2

Posted: Wed Apr 30, 2003 3:48 am
by twigletmac

Posted: Wed Apr 30, 2003 9:19 am
by maxi
I've just tried with serialize() and unserialize() and it didn't work.
I lost the reference of the object within pages using $_SESSION independently if i use serialize() or not.

Posted: Wed Apr 30, 2003 1:04 pm
by maxi
I'm trying to store a COM object in a session but I've just read that php can't store a COM object in a session. It's true? Is there any patch to fix it?

Posted: Wed Apr 30, 2003 1:55 pm
by volka
php (by default) stores sessions in flat files. Everything is casted to string before saved. But that doesn't work for objects esp. not for COM-objects. If you're lucky the COM-object itself implements some kind of persistence-interface, so you can invoke it when serializing your data.

Posted: Wed Apr 30, 2003 2:13 pm
by maxi
What I have mentioned about storing COM object in a session I got it from the manual of PHP in "FAQ: Frequently Asked Questions" -> "PHP and COM"

"4. Can I store a COM object in a session ?

No, you can't. COM instances are treated as resources and therefore they are only available in a single script's context. "
(http://www.php.net/manual/en/faq.com.php#faq.com.q4)

So, when i store a com-object in a session variable doing:
$_SESSION("myObject") = serialize($myObject);

I can't restore the object (in another page) doing:
$myObject = unserialize($_SESSION("myObject");

Posted: Wed Apr 30, 2003 2:18 pm
by volka
that's correct.
But some COM-components implement their own persistence mechanism, that you might call to store the object. That's a rather long shot but the best I can offer ;)

Posted: Wed Apr 30, 2003 3:37 pm
by maxi
Ok, thanks you very much.
I'll see what can i do...