Ask a Question related to PHP Development, Design and Development.
-
Goldfisch1980 #1
Loading of 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
Goldfisch1980 Guest
-
#25970 [Bgs]: Session management fails when I stop the browser while a PHP page is loading.
ID: 25970 User updated by: bueno at catho dot com dot br -Reported By: catia at catho dot com dot br +Reported By: bueno... -
#25970 [Opn->Bgs]: Session management fails when I stop the browser while a PHP page is loading.
ID: 25970 Updated by: sniper@php.net Reported By: catia at catho dot com dot br -Status: Open +Status: ... -
#25970 [NoF->Opn]: Session management fails when I stop the browser while a PHP page is loading.
ID: 25970 User updated by: catia at catho dot com dot br Reported By: catia at catho dot com dot br -Status: No... -
#25970 [Opn->Fbk]: Session management fails when I stop the browser while a PHP page is loading.
ID: 25970 Updated by: iliaa@php.net Reported By: catia at catho dot com dot br -Status: Open +Status: ... -
#25970 [Fbk->Opn]: Session management fails when I stop the browser while a PHP page is loading.
ID: 25970 User updated by: catia at catho dot com dot br Reported By: catia at catho dot com dot br -Status: ... -
Colin McKinnon #2
Re: Loading of Class Object passed via PHP Session fails!
Goldfisch1980 spilled the following:
<snip>> 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 assume you mean that register_globals=off> I don't use GLOBALS = ON
Problems:>
> -------------------------------------------------
> // 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();
> ....
> -------------------------------------------------
>
1) there's nowhere in the code for site A which actually sends the
parameters to site B. I don't know how to POST from a php script without
doing a lot of low level stuff with sockets or routing it through a browser
(anybody know?). You could try GET, but serialized objects take up rather a
lot of space and ISR that there is a limit on the size of a URI.
2) If register_globals=off, you need to specifically reference any
parameters in site B or import them into the scope. (e.g.
$art=$_POST['art'])
3) you don't unserialize the value in the site 'B' script
4) since the rest of your code isn't particularly OO, you might find an
associative array less expensive.
Sessions work by storing a bundle of information server-side - the html>
> How is it possible, to receive the complete object via a php session on
> the next site??
>
pages sent to the browser get a handle (the SID) either as a parameter to
be attached to any URLs it fetches, or more commonly as a cookie. If you
want more than one server to be able to see the server-side bundle then you
need need a direct line of comunication between them. The simplest solution
is a shared filesystem (sessions are stored as files by default) but can
also be stored in databases. (i.e. using the session to get the parameters
from site A to site B will not offer any advantage).
HTH
C.
Colin McKinnon Guest
-
Lars Plessmann #3
Re: Loading of Class Object passed via PHP Session fails!
Colin McKinnon wrote:
Well thank you..> Goldfisch1980 spilled the following:
>
>>>>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.
> <snip>
>>>>I don't use GLOBALS = ON
>
> I assume you mean that register_globals=off
>
>>>>-------------------------------------------------
>>// 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();
>>....
>>-------------------------------------------------
>>
>
> Problems:
> 1) there's nowhere in the code for site A which actually sends the
> parameters to site B. I don't know how to POST from a php script without
> doing a lot of low level stuff with sockets or routing it through a browser
> (anybody know?). You could try GET, but serialized objects take up rather a
> lot of space and ISR that there is a limit on the size of a URI.
>
> 2) If register_globals=off, you need to specifically reference any
> parameters in site B or import them into the scope. (e.g.
> $art=$_POST['art'])
>
> 3) you don't unserialize the value in the site 'B' script
>
> 4) since the rest of your code isn't particularly OO, you might find an
> associative array less expensive.
>
>>>>How is it possible, to receive the complete object via a php session on
>>the next site??
>>
>
> Sessions work by storing a bundle of information server-side - the html
> pages sent to the browser get a handle (the SID) either as a parameter to
> be attached to any URLs it fetches, or more commonly as a cookie. If you
> want more than one server to be able to see the server-side bundle then you
> need need a direct line of comunication between them. The simplest solution
> is a shared filesystem (sessions are stored as files by default) but can
> also be stored in databases. (i.e. using the session to get the parameters
> from site A to site B will not offer any advantage).
>
> HTH
>
> C.
I've solved the problem now :)
Lars Plessmann Guest



Reply With Quote

