Storing objects in PHP session

后端 未结 5 2142
悲&欢浪女
悲&欢浪女 2020-11-29 02:24

The PHP documentation says \"You can\'t use references in session variables as there is no feasible way to restore a reference to another variable.\"

Does this mean

5条回答
  •  温柔的废话
    2020-11-29 03:11

    For safe serialization and unserialization encode and decode with base64_encode() and base64_decode() respectively. Below I pass a serialized Object to a session and unserialize it on the other page to regain the variable to an object state.

    Page 1

    setUserRegData();
    $reg_serlizer = base64_encode(serialize($registrationData));   //serilize the object to create a string representation
    $_SESSION['regSession'] = $reg_serlizer;
    ?>
    

    Page 2

    firstName;
    ?>
    

    This article describes issues that may be faced by not doing so. issuses with php serialization/unserialization

提交回复
热议问题