By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

serialize() and unserialize()

P: n/a
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 =
unserialize(base64_decode($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 =
PHP.TypeSupport.ToString(unserialize(base64_decode (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?

Dec 20 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
<po******@masters.eduwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
I've just taken over a PHP website and am converting it to ASP.NET

See, there's your problem, right there. Just don't do that and you're fine.
Dec 20 '06 #2

P: n/a
po******@masters.edu wrote:
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 =
unserialize(base64_decode($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 =
PHP.TypeSupport.ToString(unserialize(base64_decode (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?
There is equivalent functionality available in .NET. Googled it...

http://www.411asp.net/func/search?tr...at=all&x=0&y=0
http://www.google.com/search?q=base6...&start=10&sa=N

Dec 20 '06 #3

P: n/a
powellgg wrote:
.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?
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
cookie.

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:

http://csphpserial.sf.net/

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 ~ http://tobyinkster.co.uk/contact

Dec 20 '06 #4

P: n/a

po******@masters.edu schrieb:
.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?
..Net has serialization support, as many other languages too:

http://www.codeguru.com/columns/DotN...cle.php/c6595/

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

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

Dec 20 '06 #5

P: n/a
... and I can't find
where the page/site does the initial serialization.
In earlier versions of PHP, it was normal that page parameters were
visible in scripts as variables. So if you requested
http://www.example.com/index.php?user=john , 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.
http://www.kratz.nl/
Dec 20 '06 #6

P: n/a
True... but this is what they hired me for :).
Kimmo Laine wrote:
<po******@masters.eduwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
I've just taken over a PHP website and am converting it to ASP.NET


See, there's your problem, right there. Just don't do that and you're fine.
Dec 21 '06 #7

P: n/a
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:
powellgg wrote:
.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?

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
cookie.

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:

http://csphpserial.sf.net/

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 ~ http://tobyinkster.co.uk/contact
Dec 21 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.