Jump to content

Unserialize, then Serialize back


JREAM

Recommended Posts

Guys I have been trying to do this forever now!

Doing unserialize($code); var_dump($code); but when i copy the output to serialize it again and put it in, it doesn't work.

 

I want to change titles to things, I can kind of read through it, a:7 = 7 arrays, s:13 = String 13 chars, but its multi-dimensional and gets confusing.

 

Can anyone help me unscramble this so i can retype some names, then serialize it again to put back?

I have read the PHP serialize/unserialize pages a lot but cant figure it out

 

Here is the code Im trying to do it with:

a:7:{s:8:"homepage";i:1;s:10:"links_cats";a:4:{s:7:"sidebar";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}s:11:"other-pages";a:0:{}s:14:"top-navigation";a:2:{i:0;s:1:"1";i:1;s:1:"4";}s:12:"Footer-Right";a:3:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"3";}}s:5:"slugs";a:4:{i:1;s:4:"home";i:2;s:14:"how-to-install";i:3;s:7:"license";i:4;s:7:"contact";}s:6:"titles";a:4:{i:1;s:4:"Home";i:2;s:15:"How to Install?";i:3;s:7:"License";i:4;s:7:"Contact";}s:10:"slug_count";i:9;s:8:"settings";a:3:{s:19:"index-last-modified";i:1195461128;s:18:"def-template-areas";a:4:{i:0;s:12:"WebSite Name";i:2;s:14:"WebSite slogan";i:3;s:16:"Below Navigation";i:4;s:16:"Copyright Notice";}s:18:"def-template-links";a:2:{i:0;s:14:"top-navigation";i:1;s:12:"Footer-Right";}}s:13:"active-tweaks";a:0:{}}

Link to comment
https://forums.phpfreaks.com/topic/123609-unserialize-then-serialize-back/
Share on other sites

If you var_export() the unserialized data, you can edit what you desire, and then serialize it again. It'll work because var_export() outputs/returns valid PHP (var_dump() and print_r() don't).

 

<?php
$data = 'a:7:{s:8:"homepage";i:1;s:10:"links_cats";a:4:{s:7:"sidebar";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}s:11:"other-pages";a:0:{}s:14:"top-navigation";a:2:{i:0;s:1:"1";i:1;s:1:"4";}s:12:"Footer-Right";a:3:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"3";}}s:5:"slugs";a:4:{i:1;s:4:"home";i:2;s:14:"how-to-install";i:3;s:7:"license";i:4;s:7:"contact";}s:6:"titles";a:4:{i:1;s:4:"Home";i:2;s:15:"How to Install?";i:3;s:7:"License";i:4;s:7:"Contact";}s:10:"slug_count";i:9;s:8:"settings";a:3:{s:19:"index-last-modified";i:1195461128;s:18:"def-template-areas";a:4:{i:0;s:12:"WebSite Name";i:2;s:14:"WebSite slogan";i:3;s:16:"Below Navigation";i:4;s:16:"Copyright Notice";}s:18:"def-template-links";a:2:{i:0;s:14:"top-navigation";i:1;s:12:"Footer-Right";}}s:13:"active-tweaks";a:0:{}}';
echo '<pre>', var_export(unserialize($data), true), '</pre>';
?>

 

Output:

array (
  'homepage' => 1,
  'links_cats' => 
  array (
    'sidebar' => 
    array (
      0 => 1,
      1 => 2,
      2 => 3,
      3 => 4,
    ),
    'other-pages' => 
    array (
    ),
    'top-navigation' => 
    array (
      0 => '1',
      1 => '4',
    ),
    'Footer-Right' => 
    array (
      0 => '1',
      1 => '4',
      2 => '3',
    ),
  ),
  'slugs' => 
  array (
    1 => 'home',
    2 => 'how-to-install',
    3 => 'license',
    4 => 'contact',
  ),
  'titles' => 
  array (
    1 => 'Home',
    2 => 'How to Install?',
    3 => 'License',
    4 => 'Contact',
  ),
  'slug_count' => 9,
  'settings' => 
  array (
    'index-last-modified' => 1195461128,
    'def-template-areas' => 
    array (
      0 => 'WebSite Name',
      2 => 'WebSite slogan',
      3 => 'Below Navigation',
      4 => 'Copyright Notice',
    ),
    'def-template-links' => 
    array (
      0 => 'top-navigation',
      1 => 'Footer-Right',
    ),
  ),
  'active-tweaks' => 
  array (
  ),
)

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.