473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

serialize() and unserialize()

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
7 3533
<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
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
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

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
... 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James Sleeman | last post by:
Hi all, i just spent an hour rifling through code to find the cause of a problem only to find it's an oddity with serialization and recursive objects, so figured I'd post for the next person who...
8
by: John Smith | last post by:
Hi, I am using a custom Session Handler. session_set_save_handler is working well. But i want to read the data direct from the database. My problem: php don't uses the standard serialize...
2
by: Andrew | last post by:
Some have suggested that using serialize() and unserialize is faster than reading/writing an array to disk as a simple text file using $array = file('numbers.txt'); Can anyone justify this? ...
7
by: richbl | last post by:
Hello all, I have a question about unserializing a single array element from a serialized array. Can this be done, or must I first unserialize the array, and then access the element? For...
6
by: sandy | last post by:
With java servlets I can declare complex object-oriented class structures as session variables in a servlet. That means I can have a complex HTML form that submits iteratively back to the server...
2
by: onefastmustang | last post by:
I have a cookie that I serialize and set as follows.. $searchdata = $state; $searchdata = $country; $searchdata = $radius; $searchdata = $radius_zip; if ($_GET){ foreach ($_GET as $value){...
1
by: Mark | last post by:
I'd like to take an instance of a class, and serialize it to a file on my computer. No security required on the file. Then, I'd like to be able to unserialize the file later and use the instance...
2
by: Derek Martin | last post by:
Hey list, I have an arraylist containing some objects that I want to serialize and send over the internet and then deserialize back into the arraylist of objects. What I have so far: Dim...
1
by: VooDoo | last post by:
Hi, I am using the serialize and unserialize to put and get data from mysql database. I think i could optimise the way i handle the data, but not really sure how. What is the best way to happend...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.