Jump to content

Sending a serialized php object via Ajax


Zaxnyd

Recommended Posts

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

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;
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.