0

I am saving an serialized array in mysql database . and when i fetching result data from mysql and printing that details it is printing .

 $data=$row['data'];



print_r( $data)

result is

a:8:{i:0;a:7:{s:2:"id";s:2:"16";s:4:"slug";s:8:"fieldset";s:4:"name";s:8:"Fieldset";s:4:"type";s:8:"fieldset";s:7:"options";s:0:"";s:9:"parent_id";s:1:"0";s:5:"value";s:0:"";}i:1;a:7:{s:2:"id";s:2:"20";s:4:"slug";s:9:"your-name";s:4:"name";s:9:"Your Name";s:4:"type";s:4:"text";s:7:"options";s:0:"";s:9:"parent_id";s:1:"0";s:5:"value";s:11:"SamueljalIL";}i:2;a:7:{s:2:"id";s:2:"21";s:4:"slug";s:10:"your-email";s:4:"name";s:10:"Your Email";s:4:"type";s:5:"email";s:7:"options";s:0:"";s:9:"parent_id";s:1:"0";s:5:"value";s:16:"dimitryg@msn.com";}i:3;a:7:{s:2:"id";s:2:"24";s:4:"slug";s:5:"phone";s:4:"name";s:5:"Phone";s:4:"type";s:4:"text";s:7:"options";s:0:"";s:9:"parent_id";s:1:"0";s:5:"value";s:11:"88621295115";}i:4;a:7:{s:2:"id";s:2:"22";s:4:"slug";s:12:"your-message";s:4:"name";s:12:"Your Message";s:4:"type";s:8:"textarea";s:7:"options";s:0:"";s:9:"parent_id";s:1:"0";s:5:"value";s:1876:"Havе yоu listenеd
 http://boletines.consumer.es/?p=50&u=https://gdfgl/96D4u9";}i:5;a:7:{s:2:"id";s:2:"17";s:4:"slug";s:12:"verification";s:4:"name";s:12:"Verification";s:4:"type";s:12:"verification";s:7:"options";s:0:"";s:9:"parent_id";s:1:"0";s:5:"value";s:0:"";}i:6;a:7:{s:2:"id";s:2:"18";s:4:"slug";s:27:"please-enter-any-two-digits";s:4:"name";s:27:"Please enter any two digits";s:4:"type";s:6:"secret";s:7:"options";s:0:"";s:9:"parent_id";s:2:"17";s:5:"value";s:2:"82";}i:7;a:7:{s:2:"id";s:2:"19";s:4:"slug";s:6:"submit";s:4:"name";s:6:"Submit";s:4:"type";s:6:"submit";s:7:"options";s:0:"";s:9:"parent_id";s:2:"17";s:5:"value";s:0:"";}} 

But when i try to unserilize this data it is not working

 $arr=unserialize($data);

  print_r($arr);

there is nothing printing here ;

Abilash Erikson
  • 341
  • 4
  • 26
  • 55

2 Answers2

1

Your serialized string has been damaged. As I rub my crystal ball, I can imagine someone manually performed string replacements (inappropriately) to update the url that immediately follows Have you listened in the array at index 4.

This is revealed after analyzing the data at this location:

s:1876:"Havе yоu listenеd
http://boletines.consumer.es/?p=50&u=https://gdfgl/96D4u9";

You see this stored value has 81 bytes/characters in it.

The serialized data strictly claims that the value must have 1876 bytes/characters in it.

Ultimately, your serialized data has been compromised -- either the length or the value.

If you are not bothered by the current value, you can manually repair the serialized data with this: https://3v4l.org/GqsHu

This is from a post of mine here: https://stackoverflow.com/a/55074706/2943403

With the provided snippet, you can either repair the corrupted serialized data on the fly each time, or you can take the time to repair all corrupted data and update your database so that this headache doesn't present itself again.

Let this occurrence be a lesson to developers -- Never try to take a short cut to update serialized data. You must unserialize it, modifying it, then re-serialize it so that a valid string is generated.

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
  • could you please help me to fetch the online gold price from google or any other api ? If you can i will make it as other question – Abilash Erikson Apr 07 '19 at 10:48
  • I am not at my computer anymore, I am spending time with my family. When you post your question, be sure to include your research and best coding attempt. – mickmackusa Apr 07 '19 at 11:15
0

I think your serilized data truncate when storing into database. it might happen due to column length size. So increase you column length and try.

Sohel Rana
  • 567
  • 5
  • 10
  • bu ti have enough column length . And there error is not due to column length . – Abilash Erikson Jul 11 '18 at 11:15
  • What is the column type you have... VER/CHAR/TEXT? It's really important to know. I had the same issue. I had 'TEXT' as column type and after that, I change that to MEDIUMTEXT. – Sohel Rana Jul 11 '18 at 11:19