Jump to content

[SOLVED] 2 questions


Ninjakreborn

Recommended Posts

serialize is good for storing an array in a single database table/cookie or any other form of storage. Sessions get their data serialize.

 

If you want to use the serialized data then you can use unserialize, to un-serialize the data.

 

Example (Using a Cookie):

 

<?php

if(!isset($_COOKIE['test']))
{
    // some dummy data will do
    $data = array('username' => 'foobar', 'age' => 50);

    // serialize the data to be stored in the cookie
    // The serialized string:
    // a:2:{s:8:"username";s:6:"foobar";s:3:"age";i:50;}
    $cookie_data = serialize($data);

    // set the cookie
    setcookie('test', $cookie_data, time()+3600);

    echo '<a href="?p=2">Get the cookie!</a>';
}
else
{
    echo 'Get the cookie:<br /><br />
Cookie recieved (<i>serialized string</i>):<br />' . $_COOKIE['test'] . '<br /><br />';

echo 'Unserialize cookie:<br /><br />';

$test_cookie = unserialize($_COOKIE['test']);

echo 'Cookie unserilized<br /><br />Contents of cookie: <pre>' . print_r($test_cookie, true) . '</pre>';

}

?>

 

Output buffering is good for creating a cache. heres a good tutorial that creates a basic cache.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.