473,382 Members | 1,329 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,382 software developers and data experts.

unserialize

I finally got serialize to work but now I cannot get unserialize to work. Here is my code.
$settings = serialize($settings_array);
echo "<INPUT TYPE='Hidden' NAME='settings' VALUE='".$settings."'>";
$settings = $_REQUEST['settings'];
echo "<P>us=".$settings;
$settings_array = Array();
$settings_array = unserialize($settings);
//if($debug) {
echo "<P> SETTINGS ARRAY <P>";
print_r($settings_array);
echo "<P>";
//}
$settings shows the unserialized data.

us=a:3:{s:2:\"id\";s:1:\"0\";s:5:\"fname\";s:1:\"x \";s:5:\"lname\";s:1:\"x\";}

but nothing is showing up for the array $settings_array when I do a print_r.

Where have I gone wrong? All help is appreciated. Thanks.

Mike

Dec 12 '05 #1
5 3748
Check your data that comes in $_REQUEST['settings'] it will most likely
have to be URL decoded to work properly with the unserializer. This
might work better:
$settings = rawurldecode($_REQUEST['settings']);

Debug outputting with <p> is a bad idea since url encoded characters
will be interpreted by the browser.

Dec 12 '05 #2
*** Mike escribió/wrote (Mon, 12 Dec 2005 18:56:37 GMT):
us=a:3:{s:2:\"id\";s:1:\"0\";s:5:\"fname\";s:1:\"x \";s:5:\"lname\";s:1:\"x\";}


When I try to unserialize this string I get this error:

Notice: unserialize(): Error at offset 0 of 78 bytes in C:\tmp\borrame.php
on line 3

It sounds like you don't have PHP configured to display notices. Add this
to top of your code:

error_reporting(E_ALL);

Also, apparently you have magic_quotes_gpc on so PHP is adding \ to all
your quotes, so " becomes \" when you read it. I suggest you edit php.ini
and set magic off:

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(),
etc.
magic_quotes_runtime = Off

If you cannot reconfigure your host, then you need further coding. Ask for
it if you need it.
--
-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--
Dec 12 '05 #3
Some other apps need magic quotes on. I guess there is no consistency about what is used. Maybe some
apps are older than others.

I tried to unserialize with urlrawencode and stripslashes and neither made a difference. I would
think that would take the slashes out. Is that correct?

I am open for more ideas. I've never used serialize/unserialize before so this is a learning
experience for me.

Thanks.

Mike
"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.com> wrote in message
news:2p****************************@40tude.net...
*** Mike escribió/wrote (Mon, 12 Dec 2005 18:56:37 GMT):
us=a:3:{s:2:\"id\";s:1:\"0\";s:5:\"fname\";s:1:\"x \";s:5:\"lname\";s:1:\"x\";}


When I try to unserialize this string I get this error:

Notice: unserialize(): Error at offset 0 of 78 bytes in C:\tmp\borrame.php
on line 3

It sounds like you don't have PHP configured to display notices. Add this
to top of your code:

error_reporting(E_ALL);

Also, apparently you have magic_quotes_gpc on so PHP is adding \ to all
your quotes, so " becomes \" when you read it. I suggest you edit php.ini
and set magic off:

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(),
etc.
magic_quotes_runtime = Off

If you cannot reconfigure your host, then you need further coding. Ask for
it if you need it.
--
-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--
Dec 12 '05 #4
*** Mike escribió/wrote (Mon, 12 Dec 2005 22:24:22 GMT):
Some other apps need magic quotes on. I guess there is no consistency about what is used. Maybe some
apps are older than others.


Then:

if(get_magic_quotes_gpc()){
$foo=stripslashes($_POST['foo']);
}
And, please believe me, always use this when coding:

error_reporting(E_ALL);

--
-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--
Dec 12 '05 #5
I was not sure that I could put that inline. Thanks for the tip.

Mike
"Alvaro G. Vicario" <we*******@NOSPAMdemogracia.com> wrote in message
news:1c****************************@40tude.net...
*** Mike escribió/wrote (Mon, 12 Dec 2005 22:24:22 GMT):
Some other apps need magic quotes on. I guess there is no consistency about what is used. Maybe
some
apps are older than others.


Then:

if(get_magic_quotes_gpc()){
$foo=stripslashes($_POST['foo']);
}
And, please believe me, always use this when coding:

error_reporting(E_ALL);

--
-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro
--
Dec 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
Greetings: So, I've got a real problem in that PHP doesn't seem to be able to unserialize() an array that has an element containing a newline. Of course, I've used htmlentities() to protect the...
1
by: Sebastian Aguilera | last post by:
Hi everyone. I have some troubles using the unserialize() function. I have serialized an array and that works perfect: echo '<input type="hidden" name="vardekedja" value="'.serialize($_POST...
1
by: Spam sucks | last post by:
Hello, Could somebody explane to me how i can unserialize the content of a session file, i allready reading the session files and the content now i only need to unserialize the data in the...
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){...
7
by: powellgg | last post by:
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...
2
by: thecoolone | last post by:
I am trying to implement the yahoo search api using php. I prefer to use PHP serialized to get the result of the search displayed. Right now i get the output like: Array ( =Array ( =web ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.