470,849 Members | 1,144 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Class Object passed via PHP Session fails!

Hello!

I try to use PHP session function, and it doesn't work properly. :-(
I want to pass a whole object from site A to site B to minimize Database
connections.

I don't use GLOBALS = ON. My param GLOBALS is set to OFF and has be be
keept off!

Well. I want to pass a complete object of class article from website A
to website B. A daily problem, I think! But it doesn't work!

Here is my Code:


-------------------------------------------------
class article
{
var $titel;
var $id;
var $verkaufsart;
var $mehrwertsteuerAusweisbar;
var $preisart;
var $verfügbarAb;
var $angebotspreis;
var $hinweise;
var $beschreibung;

function setTitel($titel) {
$this->titel = $titel;
}

function getTitel() {
return $this->titel;
}

function setId($id) {
$this->id = $id;
}

function getId() {
return $this->id;
}
}


-------------------------------------------------
// site A
<?php

include_once 'article.php';

session_start();

$art = new article();
$art2 = new article();

session_register("art");
session_register("art2");
$art->setTitel("Test");
$art->setId("15");

$art2->setTitel("Test2");
$art2->setId("16");

print $art->getId()." ".$art->getTitel();
print $art2->getId()." ".$art2->getTitel();

print "<a href=\"step2.php\">NEXT</a>";

?>


-------------------------------------------------
// site B
<?php

include_once 'article.php';

session_start();

if (!is_object($art)) $art = new article();
if (!is_object($art2)) $art2 = new article();

print $art->getId()." ".$art->getTitel();
print $art2->getId()." ".$art2->getTitel();
.....
-------------------------------------------------


By the way, when I print out the variable $_SESSION, I can see the
content of the object, but I dont have access:

Array ( [art] => article Object ( [titel] => Test [id] => 15
[verkaufsart] => [mehrwertsteuerAusweisbar] => [preisart] =>
[verfügbarAb] => [angebotspreis] => [hinweise] => [beschreibung] => )
[art2] => article Object ( [titel] => Test2 [id] => 16 [verkaufsart] =>
[mehrwertsteuerAusweisbar] => [preisart] => [verfügbarAb] =>
[angebotspreis] => [hinweise] => [beschreibung] => ) )

How is it possible, to receive the complete object via a php session on
the next site??
I hope you can help me!?
thanks in advance,

Lars
Jul 17 '05 #1
6 1739
Lars Plessmann <La************@gmx.de> wrote:
I don't use GLOBALS = ON. My param GLOBALS is set to OFF and has be be
keept off!
[your code] session_register("art");
session_register("art2");
Please read the first Caution on the session_register page:
<q>
Caution

If you want your script to work regardless of register_globals, you need
to instead use the $_SESSION array as $_SESSION entries are
automatically registered. If your script uses session_register(), it
will not work in environments where the PHP directive register_globals
is disabled.
</q>
Well. I want to pass a complete object of class article from website A
to website B. A daily problem, I think! But it doesn't work!


What is your definition of website? Normally websites don't share
sessions.

BTW your solution might be serialize:
http://nl2.php.net/manual/en/languag...ialization.php

--

Daniel Tryba

Jul 17 '05 #2
Daniel Tryba wrote:
Lars Plessmann <La************@gmx.de> wrote:
I don't use GLOBALS = ON. My param GLOBALS is set to OFF and has be be
keept off!

[your code]
session_register("art");
session_register("art2");

Please read the first Caution on the session_register page:
<q>
Caution

If you want your script to work regardless of register_globals, you need
to instead use the $_SESSION array as $_SESSION entries are
automatically registered. If your script uses session_register(), it
will not work in environments where the PHP directive register_globals
is disabled.
</q>


Well. how can I share an object then (with class definition and so on)?
I don't like to use the $_SESSION[] var.
I like to use the $obj->property form.
Well. I want to pass a complete object of class article from website A
to website B. A daily problem, I think! But it doesn't work!

What is your definition of website? Normally websites don't share
sessions.


I want to read some records from a database (articles) and display them
on click in detailled version. I don't want to make another slq request
so i think its better to load the articles an keep them in memory.

BTW your solution might be serialize:
http://nl2.php.net/manual/en/languag...ialization.php

Jul 17 '05 #3
In article <c6*************@news.t-online.com>,
Lars Plessmann <La************@gmx.de> wrote:
I don't like to use the $_SESSION[] var.
I like to use the $obj->property form.


You can still use $_SESSION['art']->property. If that doesn't look
aesthetically pleasing to you, you can always do this, I suppose:

$obj =& $_SESSION['art'];

and use the $obj->property form.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #4
Lars Plessmann <La************@gmx.de> wrote:
Well. how can I share an object then (with class definition and so on)?


Thank you for not reading the pointers I gave you.
BTW your solution might be serialize:
http://nl2.php.net/manual/en/languag...ialization.php


Hint hint, read this page...

--

Daniel Tryba

Jul 17 '05 #5
Daniel Tryba wrote:
Lars Plessmann <La************@gmx.de> wrote:
Well. how can I share an object then (with class definition and so on)?

Thank you for not reading the pointers I gave you.

BTW your solution might be serialize:
http://nl2.php.net/manual/en/languag...ialization.php

Hint hint, read this page...


Ohh. sorry. I didn't see the link. I thought it was part of the
signature. :)
Thx!
Jul 17 '05 #6
Lars Plessmann <La************@gmx.de> wrote:
BTW your solution might be serialize:
http://nl2.php.net/manual/en/languag...ialization.php

Hint hint, read this page...


Ohh. sorry. I didn't see the link. I thought it was part of the
signature. :)


Oh well, you solved you problem :)

BTW fancy newsreaders can do all kind of stuff like give different
colors to sigs

--

Daniel Tryba

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Tammy B. | last post: by
4 posts views Thread by Vedanta Barooah | last post: by
6 posts views Thread by Scott Zabolotzky | last post: by
4 posts views Thread by Diffident | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.