Likes Likes:  0
Resultaten 1 tot 15 van de 33
Pagina 1 van de 3 1 2 3 LaatsteLaatste
Geen
  1. #1
    Marcel
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Passing objects from one page to another

    I have a person class adn i want to derive an object of that class on one
    page and pass that object to a next page but that does not work for me and i
    do not understand why.

    Here is de code:

    class.person.php
    -----------------------------------
    class person {

    private $_name;

    public function setName($name) {

    $this->_name = $name;

    }

    public function getName() {

    return $this->_name;

    }

    }
    --------------------------------------------



    person1.php // here is the object created
    -------------------------------------------
    require_once("class.person.php");

    $p = new person();

    $p->setName("Jim");

    $safep = urlencode(serialize($p));

    header("Locationerson2.php?data=".$safep);

    exit;


    person2.php // page where the object is transfered to
    ---------------------------------------------------
    require_once("class.person.php");

    $p = unserialize(urldecode($_GET['data']));

    echo $p->getName();



  2. #2
    Marcel
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another


    "Marcin Dobrucki" <Marcin.Dobrucki@TAKETHISAWAY.nokia.com> schreef in
    bericht news:VKm4h.42491$_k2.774821@news2.nokia.com...
    > Marcel wrote:
    >
    >> Yes you are right, the errorcode i am getting is:
    >>
    >> Fatal error: Call to a member function getName() on a non-object in
    >> D:\public_html\person2.php on line 7

    >
    > One step at a time: what do you get out of "urldecode" and then what do
    > you get from "unserialize"? Check the return values.


    It seems the unserialize function does not seem to work properly... i will
    do a little research at that first ok...



  3. #3
    Marcin Dobrucki
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    Marcel wrote:

    > Yes you are right, the errorcode i am getting is:
    >
    > Fatal error: Call to a member function getName() on a non-object in
    > D:\public_html\person2.php on line 7


    One step at a time: what do you get out of "urldecode" and then what
    do you get from "unserialize"? Check the return values.

  4. #4
    Marcel
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another


    "Marcin Dobrucki" <Marcin.Dobrucki@TAKETHISAWAY.nokia.com> schreef in
    bericht news:lJm4h.42490$_k2.774821@news2.nokia.com...
    > Marcel wrote:
    >> I have a person class adn i want to derive an object of that class on one
    >> page and pass that object to a next page but that does not work for me
    >> and i do not understand why.

    > ...
    > I tried this code, and it works just fine. You didn't include the rest of
    > the code, so maybe there is something there that breaks it?
    >
    > <?php
    > class A {
    > var $name;
    > function A($name) {
    > $this->name = $name; }
    > function getName() {
    > return $this->name; }
    > }
    >
    > $a = new A("my name");
    > $a_serialized = urlencode(serialize($a));
    > header("Location: obj2.php?data=".$a_serialized);
    > ?>
    >
    > and:
    >
    > <?php
    > class A {
    > var $name;
    > function A($name) {
    > $this->name = $name; }
    > function getName() {
    > return $this->name; }
    > }
    >
    > $a = unserialize(urldecode($_GET['data']));
    > echo get_class($a);
    > echo "<br>";
    > echo $a->getName();
    > ?>


    Hi Marcin,

    I tried your example but i am getting the same error: Call to a member
    function getName() on a non-object in

    Maybe it is a php.ini issue? I do not know what can be another reason....
    maybe magicquotes have to do something with this?

    Do you have any ideas?

    Marcel




  5. #5
    Marcin Dobrucki
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    Marcel wrote:
    > I have a person class adn i want to derive an object of that class on one
    > page and pass that object to a next page but that does not work for me and i
    > do not understand why.

    ....
    I tried this code, and it works just fine. You didn't include the rest
    of the code, so maybe there is something there that breaks it?

    <?php
    class A {
    var $name;
    function A($name) {
    $this->name = $name; }
    function getName() {
    return $this->name; }
    }

    $a = new A("my name");
    $a_serialized = urlencode(serialize($a));
    header("Location: obj2.php?data=".$a_serialized);
    ?>

    and:

    <?php
    class A {
    var $name;
    function A($name) {
    $this->name = $name; }
    function getName() {
    return $this->name; }
    }

    $a = unserialize(urldecode($_GET['data']));
    echo get_class($a);
    echo "<br>";
    echo $a->getName();
    ?>

  6. #6
    Marcel
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another


    "ZeldorBlat" <zeldorblat@gmail.com> schreef in bericht
    news:1162998447.934912.233680@i42g2000cwa.googlegr oups.com...
    >
    > Marcel wrote:
    >> I have a person class adn i want to derive an object of that class on one
    >> page and pass that object to a next page but that does not work for me
    >> and i
    >> do not understand why.
    >>
    >> Here is de code:
    >>
    >> class.person.php
    >> -----------------------------------
    >> class person {
    >>
    >> private $_name;
    >>
    >> public function setName($name) {
    >>
    >> $this->_name = $name;
    >>
    >> }
    >>
    >> public function getName() {
    >>
    >> return $this->_name;
    >>
    >> }
    >>
    >> }
    >> --------------------------------------------
    >>
    >>
    >>
    >> person1.php // here is the object created
    >> -------------------------------------------
    >> require_once("class.person.php");
    >>
    >> $p = new person();
    >>
    >> $p->setName("Jim");
    >>
    >> $safep = urlencode(serialize($p));
    >>
    >> header("Locationerson2.php?data=".$safep);
    >>
    >> exit;
    >>
    >>
    >> person2.php // page where the object is transfered to
    >> ---------------------------------------------------
    >> require_once("class.person.php");
    >>
    >> $p = unserialize(urldecode($_GET['data']));
    >>
    >> echo $p->getName();

    >
    > Difficult to say since you haven't told us what doesn't work. As in
    > you get some error that you can't unserialize it? Or no error at all
    > (as in your error reporting is turned off)?
    >
    > My guess would be that
    > $p = unserialize(urldecode($_GET['data']));
    > should really be just
    > $p = unserialize($_GET['data']);
    >
    > But I didn't test it.
    >


    Yes you are right, the errorcode i am getting is:

    Fatal error: Call to a member function getName() on a non-object in
    D:\public_html\person2.php on line 7

    Regards,

    Marcel



  7. #7
    ZeldorBlat
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another


    Marcel wrote:
    > I have a person class adn i want to derive an object of that class on one
    > page and pass that object to a next page but that does not work for me and i
    > do not understand why.
    >
    > Here is de code:
    >
    > class.person.php
    > -----------------------------------
    > class person {
    >
    > private $_name;
    >
    > public function setName($name) {
    >
    > $this->_name = $name;
    >
    > }
    >
    > public function getName() {
    >
    > return $this->_name;
    >
    > }
    >
    > }
    > --------------------------------------------
    >
    >
    >
    > person1.php // here is the object created
    > -------------------------------------------
    > require_once("class.person.php");
    >
    > $p = new person();
    >
    > $p->setName("Jim");
    >
    > $safep = urlencode(serialize($p));
    >
    > header("Locationerson2.php?data=".$safep);
    >
    > exit;
    >
    >
    > person2.php // page where the object is transfered to
    > ---------------------------------------------------
    > require_once("class.person.php");
    >
    > $p = unserialize(urldecode($_GET['data']));
    >
    > echo $p->getName();


    Difficult to say since you haven't told us what doesn't work. As in
    you get some error that you can't unserialize it? Or no error at all
    (as in your error reporting is turned off)?

    My guess would be that
    $p = unserialize(urldecode($_GET['data']));
    should really be just
    $p = unserialize($_GET['data']);

    But I didn't test it.


  8. #8
    Michael Fesser
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    ..oO(Marcel)

    >I tried your example but i am getting the same error: Call to a member
    >function getName() on a non-object in


    error_reporting set to E_ALL? What browser do you use?

    >Maybe it is a php.ini issue? I do not know what can be another reason....
    >maybe magicquotes have to do something with this?


    First you should fix the error in the redirect. The Location header
    requires an absolute URL.

    Micha

  9. #9
    Marcel
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another


    "Marcin Dobrucki" <Marcin.Dobrucki@TAKETHISAWAY.nokia.com> schreef in
    bericht news:VKm4h.42491$_k2.774821@news2.nokia.com...
    > Marcel wrote:
    >
    >> Yes you are right, the errorcode i am getting is:
    >>
    >> Fatal error: Call to a member function getName() on a non-object in
    >> D:\public_html\person2.php on line 7

    >
    > One step at a time: what do you get out of "urldecode" and then what do
    > you get from "unserialize"? Check the return values.


    The unserialize function in person2.php did not return anything. I tried all
    scripts on another server with the same PHP version installed and there
    everything just worked fine. One difference i can think of is the fact that
    the server where my script did not work is protected trough https



  10. #10
    thehuby@gmail.com
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    Wouldn't you be better using sessions?

    If you register a session variable you won't need to use the query
    string and you won't need to serialize and deserialise it.

    Take a look at http://uk2.php.net/manual/en/ref.session.php for some
    more details.

    Rick
    www.e-connected.com




  11. #11
    Marcin Dobrucki
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    Michael Fesser wrote:
    > First you should fix the error in the redirect. The Location header
    > requires an absolute URL.


    True. But it seems to work with relative URLs as well.

  12. #12
    Jerry Stuckle
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    Marcel wrote:
    > "Marcin Dobrucki" <Marcin.Dobrucki@TAKETHISAWAY.nokia.com> schreef in
    > bericht news:VKm4h.42491$_k2.774821@news2.nokia.com...
    >
    >>Marcel wrote:
    >>
    >>
    >>>Yes you are right, the errorcode i am getting is:
    >>>
    >>>Fatal error: Call to a member function getName() on a non-object in
    >>>D:\public_html\person2.php on line 7

    >>
    >> One step at a time: what do you get out of "urldecode" and then what do
    >>you get from "unserialize"? Check the return values.

    >
    >
    > The unserialize function in person2.php did not return anything. I tried all
    > scripts on another server with the same PHP version installed and there
    > everything just worked fine. One difference i can think of is the fact that
    > the server where my script did not work is protected trough https
    >
    >


    Marcel,

    http vs. https shouldn't make a difference, unless you're trying to mix
    the two. That is, storing it in the session when using http and reading
    it back with https (or vice versa).

    Also, is the domain *exactly* the same? i.e. you don't have one as
    www.example.com and the other as example.com?

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attglobal.net
    ==================

  13. #13
    Michael Fesser
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    ..oO(Marcin Dobrucki)

    >Michael Fesser wrote:
    >> First you should fix the error in the redirect. The Location header
    >> requires an absolute URL.

    >
    > True. But it seems to work with relative URLs as well.


    A bug is a bug and should be fixed, especially if you're searching for
    the reason of another bug, which could be caused by the first.

    Micha

  14. #14
    Michael Fesser
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    ..oO(Marcin Dobrucki)

    >Michael Fesser wrote:
    >> First you should fix the error in the redirect. The Location header
    >> requires an absolute URL.

    >
    > True. But it seems to work with relative URLs as well.


    A bug is a bug and should be fixed, especially if you're searching for
    the reason of another bug, which could be caused by the first.

    Micha

  15. #15
    Michael Fesser
    Passing objects from one page to another
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: Passing objects from one page to another

    ..oO(Marcin Dobrucki)

    >Michael Fesser wrote:
    >> First you should fix the error in the redirect. The Location header
    >> requires an absolute URL.

    >
    > True. But it seems to work with relative URLs as well.


    A bug is a bug and should be fixed, especially if you're searching for
    the reason of another bug, which could be caused by the first.

    Micha

Pagina 1 van de 3 1 2 3 LaatsteLaatste

Webhostingtalk.nl

Contact

  • Rokin 113-115
  • 1012 KP, Amsterdam
  • Nederland
  • Contact
© Copyright 2001-2021 Webhostingtalk.nl.
Web Statistics