unserialize

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    unserialize

    I finally got serialize to work but now I cannot get unserialize to work. Here is my code.


    $settings = serialize($sett ings_array);
    echo "<INPUT TYPE='Hidden' NAME='settings' VALUE='".$setti ngs."'>";


    $settings = $_REQUEST['settings'];
    echo "<P>us=".$setti ngs;
    $settings_array = Array();
    $settings_array = unserialize($se ttings);
    //if($debug) {
    echo "<P> SETTINGS ARRAY <P>";
    print_r($settin gs_array);
    echo "<P>";
    //}


    $settings shows the unserialized data.

    us=a:3:{s:2:\"i d\";s:1:\"0\";s :5:\"fname\";s: 1:\"x\";s:5:\"l name\";s:1:\"x\ ";}

    but nothing is showing up for the array $settings_array when I do a print_r.

    Where have I gone wrong? All help is appreciated. Thanks.

    Mike



  • Dennis Ålund

    #2
    Re: unserialize

    Check your data that comes in $_REQUEST['settings'] it will most likely
    have to be URL decoded to work properly with the unserializer. This
    might work better:
    $settings = rawurldecode($_ REQUEST['settings']);

    Debug outputting with <p> is a bad idea since url encoded characters
    will be interpreted by the browser.

    Comment

    • Alvaro G. Vicario

      #3
      Re: unserialize

      *** Mike escribió/wrote (Mon, 12 Dec 2005 18:56:37 GMT):[color=blue]
      > us=a:3:{s:2:\"i d\";s:1:\"0\";s :5:\"fname\";s: 1:\"x\";s:5:\"l name\";s:1:\"x\ ";}[/color]

      When I try to unserialize this string I get this error:

      Notice: unserialize(): Error at offset 0 of 78 bytes in C:\tmp\borrame. php
      on line 3

      It sounds like you don't have PHP configured to display notices. Add this
      to top of your code:

      error_reporting (E_ALL);

      Also, apparently you have magic_quotes_gp c on so PHP is adding \ to all
      your quotes, so " becomes \" when you read it. I suggest you edit php.ini
      and set magic off:

      ; Magic quotes for incoming GET/POST/Cookie data.
      magic_quotes_gp c = Off

      ; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(),
      etc.
      magic_quotes_ru ntime = Off

      If you cannot reconfigure your host, then you need further coding. Ask for
      it if you need it.


      --
      -+ Álvaro G. Vicario - Burgos, Spain
      ++ http://bits.demogracia.com es mi sitio para programadores web
      +- http://www.demogracia.com es mi web de humor libre de cloro
      --

      Comment

      • Mike

        #4
        Re: unserialize

        Some other apps need magic quotes on. I guess there is no consistency about what is used. Maybe some
        apps are older than others.

        I tried to unserialize with urlrawencode and stripslashes and neither made a difference. I would
        think that would take the slashes out. Is that correct?

        I am open for more ideas. I've never used serialize/unserialize before so this is a learning
        experience for me.

        Thanks.

        Mike


        "Alvaro G. Vicario" <webmaster@NOSP AMdemogracia.co m> wrote in message
        news:2pzf7qi5t1 u6$.pwzrwuyk570 c.dlg@40tude.ne t...
        *** Mike escribió/wrote (Mon, 12 Dec 2005 18:56:37 GMT):[color=blue]
        > us=a:3:{s:2:\"i d\";s:1:\"0\";s :5:\"fname\";s: 1:\"x\";s:5:\"l name\";s:1:\"x\ ";}[/color]

        When I try to unserialize this string I get this error:

        Notice: unserialize(): Error at offset 0 of 78 bytes in C:\tmp\borrame. php
        on line 3

        It sounds like you don't have PHP configured to display notices. Add this
        to top of your code:

        error_reporting (E_ALL);

        Also, apparently you have magic_quotes_gp c on so PHP is adding \ to all
        your quotes, so " becomes \" when you read it. I suggest you edit php.ini
        and set magic off:

        ; Magic quotes for incoming GET/POST/Cookie data.
        magic_quotes_gp c = Off

        ; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(),
        etc.
        magic_quotes_ru ntime = Off

        If you cannot reconfigure your host, then you need further coding. Ask for
        it if you need it.


        --
        -+ Álvaro G. Vicario - Burgos, Spain
        ++ http://bits.demogracia.com es mi sitio para programadores web
        +- http://www.demogracia.com es mi web de humor libre de cloro
        --


        Comment

        • Alvaro G. Vicario

          #5
          Re: unserialize

          *** Mike escribió/wrote (Mon, 12 Dec 2005 22:24:22 GMT):[color=blue]
          > Some other apps need magic quotes on. I guess there is no consistency about what is used. Maybe some
          > apps are older than others.[/color]

          Then:

          if(get_magic_qu otes_gpc()){
          $foo=stripslash es($_POST['foo']);
          }


          And, please believe me, always use this when coding:

          error_reporting (E_ALL);



          --
          -+ Álvaro G. Vicario - Burgos, Spain
          ++ http://bits.demogracia.com es mi sitio para programadores web
          +- http://www.demogracia.com es mi web de humor libre de cloro
          --

          Comment

          • Mike

            #6
            Re: unserialize

            I was not sure that I could put that inline. Thanks for the tip.

            Mike


            "Alvaro G. Vicario" <webmaster@NOSP AMdemogracia.co m> wrote in message
            news:1c97xmgntr 2sp.brnyy7on6xb x.dlg@40tude.ne t...
            *** Mike escribió/wrote (Mon, 12 Dec 2005 22:24:22 GMT):[color=blue]
            > Some other apps need magic quotes on. I guess there is no consistency about what is used. Maybe
            > some
            > apps are older than others.[/color]

            Then:

            if(get_magic_qu otes_gpc()){
            $foo=stripslash es($_POST['foo']);
            }


            And, please believe me, always use this when coding:

            error_reporting (E_ALL);



            --
            -+ Álvaro G. Vicario - Burgos, Spain
            ++ http://bits.demogracia.com es mi sitio para programadores web
            +- http://www.demogracia.com es mi web de humor libre de cloro
            --


            Comment

            Working...