We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

single quote in screen name breaks unserialize of paypal_details

Development and Programming

dj-rowan's avatar
dj-rowan
31 posts
13 years ago
dj-rowan's avatar dj-rowan

I have some custom variables being sent through paypal that are important for our marketing efforts. I’m using SCM to store the purchases as per usual, but have added in my the extra values on the paypal url string I send.

This all works great 99% of the time. What i’ve found is that any instance of a single quote [ ’ ] in any of the fields causes my unserialize php script to break.

The most recent instance was someone who’s screen name was like [ xxx O’Dine ].

The only way I could track down what was breaking my php code was a painstaking serializing search which led me to the culprit.

My question is, how can I avoid this in the future? I’ve had it happen in my custom fields (sent to paypal, returned in the serialized array), and this is the first in the screen name field.

Here’s my php code that fails. I’ve tried to add some error handling into this script, but it still breaks when there’s a single quote in the serialized array.

{exp:query sql="SELECT paypal_details FROM exp_simple_commerce_purchases as p WHERE p.purchase_id={embed:purchase_id}"} {embed:purchase_id}
 <?php   
 $unserialized = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", '{paypal_details}');      
 //echo $unserialized;
 $details = @unserialize($unserialized);
  if (!is_array($details) || !isset($details['option_selection1'])) {
         // something went wrong, initialize to empty array
         echo "</td><td colspan='1'>n/a</td>";
     }
     else{
       //echo var_dump($details);
       echo "<strong>".$details['option_selection1']."</strong></td><td>".$details['option_selection2']."</td>";
     }               
 ?>
{/exp:query}

Any help would be appreciated!

thanks Rowan

       
Dan Decker's avatar
Dan Decker
7,338 posts
13 years ago
Dan Decker's avatar Dan Decker

Hi Rowan,

I think is ultimately a PHP question, and you have admittedly a lot of custom work going on here.

To get you in front of the proper audience, I’m moving this over to Development and Programing. The talented Community there should be able to get you squared away.

Cheers!

       
dj-rowan's avatar
dj-rowan
31 posts
13 years ago
dj-rowan's avatar dj-rowan

Hey Dan, Thanks for your help. I appreciate having this in front of the proper audience.

Cheers Rowan

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.