I'm referring to the order of operations:
urlencode(base64_encode(serialize($encodethis))) is not the same as base64_encode(urlencode(serialize($encodethis))).
Likewise, when you decode, unserialize(urldecode(base64_decode($decodethis))) is not the same as unserialize(base64_decode(urldecode($decodethis))).
in order to decode something that's been encoded twice, you need to decode in the opposite order: i.e., if you encode in A->B->C order, you must decode in C->B->A order (not B->C->A order, as shown in the original post).
PHP Code:
$sql = 'Some + Value';
// (note I included a character that will be affected by urlencode();
// otherwise, you might get a misleading "True" result from this test)
$urlencoded = urlencode(base64_encode(serialize($sql)));
if( $sql === unserialize(urldecode(base64_decode($urlencoded))) ){ print 'True'; }else{ print 'False'; }
// prints "False"
if( $sql === unserialize(base64_decode(urldecode($urlencoded))) ){ print 'True'; }else{ print 'False'; }
// prints "True"
// NOW, try it the other way:
$base64 = base64_encode(urlencode(serialize($sql)));
if( $sql === unserialize(urldecode(base64_decode($base64))) ){ print 'True'; }else{ print 'False'; }
// prints "True"
if( $sql === unserialize(base64_decode(urldecode($base64))) ){ print 'True'; }else{ print 'False'; }
// prints "False"
// as you can see, the results switch.
Edit:
Actually, there's no urldecode() at all. That may be the problem, too (as I said, I don't use cURL much; if this is done somewhere else along the line please LMK)
SO, unserialize(base64_decode()) is appropriate to base64_encode(serialize())
BUT is not appropriate to urlencode(base64_encode(serialize()))
In any case, thanks, midhul, for getting me to take a second look.
Connor,
What line gives you that error? place print mysql_error(); on the line after and let us know what it tells you.
Bookmarks