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...!!
LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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'];

The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.