So I need to run a serialization and then htmlspecialchars w/ ENT_QUOTES to make it safe for both a url as well as linking to that url in HTML / javascript.

I'mmm having problems decoding when I add in the ENT_QUOTES portion...

htmlspecialchars(serialize($my_array), ENT_QUOTES);
unserialize(htmlspecialchars_decode($this->getRequest()->getParam("details"))); //first line is posted to new script

I've trid the decode with the ENT_QUOTES argument, as well as messed with htmlentities with no avail. I don't think it'll be necessary to provide the data within the array, just know that it has apostrophes

cpradio
—
2013-02-15T10:50:05Z —
#2

K_Wolfe said:

So I need to run a serialization and then htmlspecialchars w/ ENT_QUOTES to make it safe for both a url as well as linking to that url in HTML / javascript.

I'mmm having problems decoding when I add in the ENT_QUOTES portion...

`php

htmlspecialchars(serialize($my_array), ENT_QUOTES);unserialize(htmlspecialchars_decode($this->getRequest()->getParam("details"))); //first line is posted to new script

`

I've trid the decode with the ENT_QUOTES argument, as well as messed with htmlentities with no avail. I don't think it'll be necessary to provide the data within the array, just know that it has apostrophes

Why do you need either of those? I would assume urlencode would be sufficient enough.

Edit:

another alternative is using base64_encode and passing the encoded value

KyleWolfe
—
2013-02-15T14:41:48Z —
#3

Hmm, I might have been testing with an extra ' at the end from my url :D. Either way I went with base64 + json_encode, thanks for the idea!

Lemon_Juice
—
2013-02-15T14:50:38Z —
#4

The thing is if you use ENT_QUOTES for htmlspecialchars() you have to use ENT_QUOTES for htmlspecialchars_decode():

And I think cpradio is right that urlencode() is probably more suited for urls - if you add serialized data to a url then most probably you pass it in the query string, in which case htmlspecialchars is not enough and the data will become corrupt on certain characters (this also applies if you use mod_rewrite so as to make nicer urls). htmlspecialchars is just a general escaping function for any data you put into html attributes and it does not cover escaping for urls.

Edit: even if you use base64_encode you need to escape the string with urlencode before putting it in the url, because base64-encoded data may contain special characters like +, / and = - you will then not be able to properly receive the data using $GET. This eventually makes base64encode not necessary for passing data via urls unless you want to add some visual obfuscation :).

cpradio
—
2013-02-15T15:22:24Z —
#5

Lemon_Juice said:

Edit: even if you use base64_encode you need to escape the string with urlencode before putting it in the url, because base64-encoded data may contain special characters like +, / and = - you will then not be able to properly receive the data using $GET. This eventually makes base64encode not necessary for passing data via urls unless you want to add some visual obfuscation :).

+1 :tup: I've run into that exact issue before. You definitely still want to use urlencode and urldecode when passing the base64 string around.

KyleWolfe
—
2013-02-15T15:35:34Z —
#6

Lemon_Juice said:

The thing is if you use ENT_QUOTES for htmlspecialchars() you have to use ENT_QUOTES for htmlspecialchars_decode():

Edit: even if you use base64_encode you need to escape the string with urlencode before putting it in the url, because base64-encoded data may contain special characters like +, / and = - you will then not be able to properly receive the data using $GET. This eventually makes base64encode not necessary for passing data via urls unless you want to add some visual obfuscation :).

Those are acceptable in a URL, and my GET is handling them correctly due to Zends mod rewrite

Lemon_Juice
—
2013-02-15T16:01:01Z —
#7

K_Wolfe said:

I said I tried that in the decode as well

Oh, I didn't notice... But can you post some sample data and code that illustrates this doesn't work? This is weird because I have tested this with data containing apostrophes and htmlspecialchars_decode works as expected.