Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can we pass object through sessions

    Hi

    in processingtransfer13.php

    session_start();
    session_register('old_balance');
    session_register('new_balance');

    $old_balance = new Balance;
    $old_balance->RetreiveBalances($retrieved_phone_number);
    $old_balance->UpdateUserBalances($retrieved_phone_number, $credit_entered);

    $new_balance = new Balance;

    $new_balance->RetreiveBalances($retrieved_phone_number);

    in transfer_process_results04.php

    <?=$old_balance->mysmsbalance;?>;//but did not display anything, could anybody tell me why

    thks in advance

    rgds

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Firstly, session_register() is deprecated, you should use:

    PHP Code:
    $_SESSION $varname
    Secondly, in order to send objects and arrays through the session you should use serialize(), then unserialize() after being passed... eg:

    PHP Code:
    <?php
    // Page1.php:
    session_start();
    $var = new object_name;
    // Do whatever...
    $_SESSION['var'] = serialize($var);


    // Page2.php
    session_start();
    $var unserialize($_SESSION['var']);
    ?>

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    how do I do a check in 2nd page?

    session_start();

    if ( isset(_$SESSION['new_balance']))
    $new_balance= unserialize(_$SESSION['new_balance']);

    OR

    $unserialize_new_balance = unserialize(_$SESSION['new_balance']);

    if ( isset($unserialize_new_balance))
    {

    }

    else
    {
    exit();
    }


    2nd question

    once unserialize, can we still unserialize again

    for example,

    the moment I press F5, compiler will complain that

    unserialize(_$SESSION['new_balance'])

    _$SESSION['new_balance'] is not a string

    but since documentation for unserialize is unserialize (string str) and I did not do like this,

    str = unserialized(str), why then I got this error

    thks
    Last edited by chleng; 09-26-2005 at 05:17 PM. Reason: Additional question


  •  

    Posting Permissions

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