• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 580
  • Last Modified:

PHP serialize and unserilize Question...?

I'm using the serialize and unserialize functions as follows
I'm using it to pass an array value to a diffrent page

$arr = unserialize(rawurldecode($_GET['filterfield']));
$arr = rawurlencode(serialize($arr));
echo $page.".php?page=$pageid&filterfield=$arr";

The only problem is that on my hosting server it doesn't work properly, it gives me a shorter string array, but on my own server it does work properly.

Suggestions are really appreciated...!!
1 Solution
I'm not sure on your requirements, but you could consider passing the information to the next page using a session variable instead. If you need help setting this up, please do let us know!
ranhellAuthor Commented:
I'm just trying to pass along 4 data fields  in an array, using the serialize and unserialize functions.
And as I mentioned before it does work on my server, but not on my hosting server, which meke me wonder why.

but anyway, how would I use a session variable...? I'll try it
I'm not sure why it wouldn't work on your other server to be honest.

As for sessions, it's very simple. First of all, on every page where you either send or receive session data, you'll need the following line. You'll need to put it somewhere before you start actually playing with the session variables, so right at the top of your page is usually a good place:


Then, you can set the data like this:

$_SESSION['filterfield'] = $_GET['filterfield'];

Or assign an array in a similar way:

$_SESSION['saved_get_vars'] = $_GET;

Then, on the next page, you can retrieve the values just as easily:

echo $_SESSION['filterfield'];

or with the array example,

echo $_SESSION['saved_get_vars']['filterfield'];

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

ranhellAuthor Commented:
This is the value i see when I hove over the next link
$_GET['filterfield'] value =a%3A4%3A%7Bi%3A0%3Bs%3A1%3A%222%22%3Bi%3A1%3Bs%3A1%3A%222%22%3Bi%3A2%3Bs%3A1%3A%222%22%3Bi%3A3%3Bs%3A1%3A%225%22%3B%7D

But somehow whe I retrieve/print the values I get just the serialize value whit a "1" at the end
Serialize value of filterfield : a:4:{i:0;s:1:\"2\";i:1;s:1:\"2\";i:2;s:1:\"2\";i:3;s:1:\"5\";}1
And then when I tried to unsierilize this value I get as follows...
Unserialize value of filterfield:1

I've also tried this, but the same results...
$arr = unserialize(urldecode($_GET['filterfield']));
$arr = urlencode(serialize($arr));
echo $page.".php?page=$pageid&filterfield=$arr";

any Ideas or suggestions
ranhellAuthor Commented:
OK, I found the solution to it, but not really sure why it happend in the first place

On my server while doing the $arr = urlencode(serialize($arr));
I would get the valu of a:4:{i:0;s:1:"2";i:1;s:1:"2";i:2;s:1:"2";i:3;s:1:"5";}

On my hosting server while doing the $arr = urlencode(serialize($arr));
I would get the valu of a:4:{i:0;s:1:\"2\";i:1;s:1:\"2\";i:2;s:1:\"2\";i:3;s:1:\"5\";}

So I add the stripslashes as follows
$arr = unserialize(urldecode(stripslashes($_GET['filterfield'])));

and now I ge the desired effect

I'm still wondering if is something to do with "magic quotes" or "real_scape_string" active on my hositng server.

Any comments...???
hello ranhell, the use of magic Quotes is a php setting that some web hosts turn it on, and other web hosts do not turn it on, it seems that on "On my hosting server" the magic quotes are functioning, you can test for magic quotes with -
if (get_magic_quotes_gpc()) {  }

which will tell you if magic_quotes is in effect or not, and may help you with your problem.
Question PAQ'd, 500 points refunded, and stored in the solution database.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now