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
https://forums.phpfreaks.com/topic/46420-solved-2-questions/#findComment-225922
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.