serialize() and unserialize()

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've just taken over a PHP website and am converting it to ASP.NET
(don't shoot!).  I'm not a PHP guy so I'm doing a lot of searching for
things that I aren't obvious, and I'm hoping I'll be able to get help
from here for things I can't find on the Internet.  Here's the first...

Here's the PHP code:

setcookie("site_search_keyword","", time() - 3600);
$site_search_keyword =

Microsoft's PHP to ASP.NET convert translated it to this:

PHP.HttpSupport.SetCookie("site_search_keyword", "",
PHP.DateTimeSupport.Time() - 3600);
site_search_keyword =

.Net has no corresponding method for unserialize() and I can't find
where the page/site does the initial serialization.  Is there an
underlying serialization when it is creating the cookie?  If the first
line is setting a null value to the cookie, why would the second line
try to read it?  It's going to be the same every time... right?

Re: serialize() and unserialize()

Quoted text here. Click to load it

See, there's your problem, right there. Just don't do that and you're fine.  

Re: serialize() and unserialize()

True... but this is what they hired me for :).

Kimmo Laine wrote:
Quoted text here. Click to load it

Re: serialize() and unserialize() wrote:
Quoted text here. Click to load it

There is equivalent functionality available in .NET. Googled it...

Re: serialize() and unserialize()

powellgg wrote:

Quoted text here. Click to load it

serialize() converts from a nested array structure to a string.
unserialize() converts back the other way. This provides a convenient
method of storing a nested array structure into a file, database or

These functions are very PHP-specific, though some people have written
functions to deal with PHP-style serialization in other languages. Of
interest to you might be:

In general though, I tend to recommend *against* rewriting code just
because it's in a language you don't know. You may have a very good
reason to be rewriting this website, but do consider whether a full
rewrite is the best solution, or whether it might be better to learn
some PHP and maintain the website that way. It's always a good idea
to expand ones repetoire of skills.

Toby A Inkster BSc (Hons) ARCS
Contact Me  ~

Re: serialize() and unserialize()

Thanks for the info!  Fortunately or unfortunately I was hired for the
purpose of doing this.  The organization went through a process of
determining whether to stay with PHP or move to .Net.  I wasn't privy
to those meetings so I have no idea what the discussions where like...
but the end result is they hired me to do this.  But I am sure I will
definitely learn some PHP along the way :)

Toby Inkster wrote:
Quoted text here. Click to load it

Re: serialize() and unserialize() schrieb:

Quoted text here. Click to load it

.Net has serialization support, as many other languages too:

In fact, each language/architeture has its own, often proprietary

In case you'd like to go xplat, you might wish to serialize into an XML

Re: serialize() and unserialize()

Quoted text here. Click to load it

In earlier versions of PHP, it was normal that page parameters were
visible in scripts as variables. So if you requested , you could use the $user
variable in your script, which would contain 'john' if you did not
overwrite that value.

So it might just be that the variable is set by another page or a form.
In this case, you'll encounter the serialization as well, so you can do
it "the .NET way".

Best regards

Willem Bogaerts

Application smith
Kratz B.V.

Site Timeline