Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Thanked 0 Times in 0 Posts

    Problem with serialize

    I have serialized an object and "added" it in a cookie. when i try to unserialize the object to a variable and call the gettype function i get as output "boolean". This is the code for unserialize:


    $connection = $HTTP_COOKIE_VARS['login'];
    $oracle = unserialize($connection);
    echo gettype($connection)."<BR>".gettype($oracle);

    the output is:

    The code for serializing the object is the following:


    $connection = serialize($oracle);
    if (setcookie("login", $connection)){
    header("Location: search.php");

    What is wrong with unserialize? I saw the manual of php and it didn't mention that returns a boolean!!!!!!! And why should return a boolean in the first placE?!?!?!?!?! Please help me with that

  2. #2
    Super Moderator
    Join Date
    May 2002
    Perth Australia
    Thanked 110 Times in 108 Posts
    theres nothing wrong with serialize, if you look again at the manual you will see

    "Never use gettype() to test for a certain type"

    instead use is_object or is_array etc , that said until we know exactly what kind of data you are serializing its hard to know...

    if you mean a true class object then that class needs to be accessible wherever you try and use it i.e. the below example is useless unless the include('s_cart.class.php'); line is there

    PHP Code:
    include 's_cart.class.php'
    $scart = new s_cart();
    so above if the session exists we reproduce our saved object , else we start a new one, again unless we include the s_cart class it wont work.

    (the session data is saved by a method of c_cart like so
    function save_as_sess(){
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


Posting Permissions

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