Re: serialize() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tedd wrote:
At 12:04 AM +0200 4/14/06, Jochem Maas wrote:

Nicholas Couloute wrote:

Are there any tutorials and uses for serialize() ? I went to php.net and it isn't well documented as I would hope!


<?php

$o = new StdObject;
$a = array();
$i = 1;
$b = false;

echo serialize($o),"\n",
     serialize($a),"\n",
     serialize($i),"\n",
     serialize($b),"\n",
     serialize(array("A"=>$o,"B"=>$a,"C"=>$i,"D"=>$b)),"\n",

?>

... and yes there are uses for it. what do you want to do?


Jochem:

Not that you don't know -- because I'm sure you do -- but for the benefit of others.

I don't know jack - just ask Jasper ;-)


One example, each domain has a limit of cookies (20) and you can use

I wasn't aware that there was a hard limit on cookies - I always thought
this was a browser dependent setting ... not that I ever get above
2 cookies max (and mostly just 1 for the session cookie).


them up pretty quickly. However, if you place your data in an array, you could then serialize the array and save it as one long string (i.e., the cookie). Then you can read it back from the cookie and un-serialize it back to the array.

I'd don't tend to do anything with cookies other than the session cookie and
keep any data in $_SESSION - saves having to cleanse whatever incoming
stuff is in the cookie (storing data on the clientside that is serialized
is can of worms waiting to happen - not that you can't code it safely per se,
it's just that much more to think about)

$_SESSION has another advantage - everything you stick in it is automagically
serialized and unserialized at end/start of the request.


tedd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux