Zaxnyd Posted April 25, 2007 Share Posted April 25, 2007 I'm looking for a failsafe way to send a serialized php object through AJAX. I posted <a href="http://www.phpfreaks.com/forums/index.php/topic,137636.0.html" target="_blank">my problem in the php section</a>, but haven't had a whole lot of luck there. Maybe you ajax pros have figured a way to do this. This is my failed attempt: (it works up until the data is passed via url, when it becomes corrupted) $serialize = serialize($myObject); $base64_encode = base64_encode($serialize); $urlencode = urlencode($base64_encode); //pass via Ajax / GET $urldecode = urldecode($urlencode ); $base64_decode = base64_decode($urldecode); $myObject= unserialize($base64_decode); Link to comment https://forums.phpfreaks.com/topic/48706-sending-a-serialized-php-object-via-ajax/ Share on other sites More sharing options...
Zaxnyd Posted April 25, 2007 Author Share Posted April 25, 2007 Solved it. It was the pesky plus sign that was doing it. So I just did an eregi_replace with a placeholder and it works wonderfully. Here's the class I made. Some of you might appreciate it: class url_serializable { function loadFromSerial($sSerial) { $urldecode = urldecode($sSerial); $urldecode = eregi_replace("--PLUS--", "\+", $urldecode); $base64_decode = base64_decode($urldecode); $unserialize = unserialize($base64_decode); return $this->loadFromObject($unserialize); } function sSerialized() { $sSerialized = $this; $sSerialized = serialize($sSerialized); $sSerialized = base64_encode($sSerialized); $sSerialized = eregi_replace("\+", "--PLUS--", $sSerialized); $sSerialized = urlencode($sSerialized); return $sSerialized; } } Link to comment https://forums.phpfreaks.com/topic/48706-sending-a-serialized-php-object-via-ajax/#findComment-238638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.