Loading of Class Object passed via PHP Session fails!

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. #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...
    2. #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: ...
    3. #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...
    4. #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: ...
    5. #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: ...
  3. #2

    Default Re: Loading of Class Object passed via PHP Session fails!

    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.
    Colin McKinnon Guest

  4. #3

    Default Re: Loading of Class Object passed via PHP Session fails!

    Colin McKinnon wrote:
    > 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.
    Well thank you..
    I've solved the problem now :)
    Lars Plessmann Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139