serialize() and unserialize()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • powellgg@masters.edu

    serialize() and unserialize()

    I've just taken over a PHP website and am converting it to ASP.NET
    (don't shoot!). I'm not a PHP guy so I'm doing a lot of searching for
    things that I aren't obvious, and I'm hoping I'll be able to get help
    from here for things I can't find on the Internet. Here's the first...

    Here's the PHP code:

    setcookie("site _search_keyword ","", time() - 3600);
    $site_search_ke yword =
    unserialize(bas e64_decode($sit e_search_keywor d));

    Microsoft's PHP to ASP.NET convert translated it to this:

    PHP.HttpSupport .SetCookie("sit e_search_keywor d", "",
    PHP.DateTimeSup port.Time() - 3600);
    site_search_key word =
    PHP.TypeSupport .ToString(unser ialize(base64_d ecode(site_sear ch_keyword)));


    ..Net has no corresponding method for unserialize() and I can't find
    where the page/site does the initial serialization. Is there an
    underlying serialization when it is creating the cookie? If the first
    line is setting a null value to the cookie, why would the second line
    try to read it? It's going to be the same every time... right?

  • Kimmo Laine

    #2
    Re: serialize() and unserialize()

    <powellgg@maste rs.eduwrote in message
    news:1166598953 .760601.100690@ 73g2000cwn.goog legroups.com...
    I've just taken over a PHP website and am converting it to ASP.NET

    See, there's your problem, right there. Just don't do that and you're fine.


    Comment

    • pangea33

      #3
      Re: serialize() and unserialize()

      powellgg@master s.edu wrote:
      I've just taken over a PHP website and am converting it to ASP.NET
      (don't shoot!). I'm not a PHP guy so I'm doing a lot of searching for
      things that I aren't obvious, and I'm hoping I'll be able to get help
      from here for things I can't find on the Internet. Here's the first...
      >
      Here's the PHP code:
      >
      setcookie("site _search_keyword ","", time() - 3600);
      $site_search_ke yword =
      unserialize(bas e64_decode($sit e_search_keywor d));
      >
      Microsoft's PHP to ASP.NET convert translated it to this:
      >
      PHP.HttpSupport .SetCookie("sit e_search_keywor d", "",
      PHP.DateTimeSup port.Time() - 3600);
      site_search_key word =
      PHP.TypeSupport .ToString(unser ialize(base64_d ecode(site_sear ch_keyword)));
      >
      >
      .Net has no corresponding method for unserialize() and I can't find
      where the page/site does the initial serialization. Is there an
      underlying serialization when it is creating the cookie? If the first
      line is setting a null value to the cookie, why would the second line
      try to read it? It's going to be the same every time... right?
      There is equivalent functionality available in .NET. Googled it...




      Comment

      • Toby Inkster

        #4
        Re: serialize() and unserialize()

        powellgg wrote:
        .Net has no corresponding method for unserialize() and I can't find
        where the page/site does the initial serialization. Is there an
        underlying serialization when it is creating the cookie? If the first
        line is setting a null value to the cookie, why would the second line
        try to read it? It's going to be the same every time... right?
        serialize() converts from a nested array structure to a string.
        unserialize() converts back the other way. This provides a convenient
        method of storing a nested array structure into a file, database or
        cookie.

        These functions are very PHP-specific, though some people have written
        functions to deal with PHP-style serialization in other languages. Of
        interest to you might be:



        In general though, I tend to recommend *against* rewriting code just
        because it's in a language you don't know. You may have a very good
        reason to be rewriting this website, but do consider whether a full
        rewrite is the best solution, or whether it might be better to learn
        some PHP and maintain the website that way. It's always a good idea
        to expand ones repetoire of skills.

        --
        Toby A Inkster BSc (Hons) ARCS
        Contact Me ~ http://tobyinkster.co.uk/contact

        Comment

        • seaside

          #5
          Re: serialize() and unserialize()


          powellgg@master s.edu schrieb:
          .Net has no corresponding method for unserialize() and I can't find
          where the page/site does the initial serialization. Is there an
          underlying serialization when it is creating the cookie? If the first
          line is setting a null value to the cookie, why would the second line
          try to read it? It's going to be the same every time... right?
          ..Net has serialization support, as many other languages too:



          In fact, each language/architeture has its own, often proprietary
          format.

          In case you'd like to go xplat, you might wish to serialize into an XML
          string.

          Comment

          • Willem Bogaerts

            #6
            Re: serialize() and unserialize()

            ... and I can't find
            where the page/site does the initial serialization.
            In earlier versions of PHP, it was normal that page parameters were
            visible in scripts as variables. So if you requested
            http://www.example.com/index.php?user=john , you could use the $user
            variable in your script, which would contain 'john' if you did not
            overwrite that value.

            So it might just be that the variable is set by another page or a form.
            In this case, you'll encounter the serialization as well, so you can do
            it "the .NET way".

            Best regards

            --
            Willem Bogaerts

            Application smith
            Kratz B.V.

            Comment

            • powellgg@masters.edu

              #7
              Re: serialize() and unserialize()

              True... but this is what they hired me for :).


              Kimmo Laine wrote:
              <powellgg@maste rs.eduwrote in message
              news:1166598953 .760601.100690@ 73g2000cwn.goog legroups.com...
              I've just taken over a PHP website and am converting it to ASP.NET
              >
              >
              See, there's your problem, right there. Just don't do that and you're fine.

              Comment

              • powellgg@masters.edu

                #8
                Re: serialize() and unserialize()

                Thanks for the info! Fortunately or unfortunately I was hired for the
                purpose of doing this. The organization went through a process of
                determining whether to stay with PHP or move to .Net. I wasn't privy
                to those meetings so I have no idea what the discussions where like...
                but the end result is they hired me to do this. But I am sure I will
                definitely learn some PHP along the way :)


                Toby Inkster wrote:
                powellgg wrote:
                >
                .Net has no corresponding method for unserialize() and I can't find
                where the page/site does the initial serialization. Is there an
                underlying serialization when it is creating the cookie? If the first
                line is setting a null value to the cookie, why would the second line
                try to read it? It's going to be the same every time... right?
                >
                serialize() converts from a nested array structure to a string.
                unserialize() converts back the other way. This provides a convenient
                method of storing a nested array structure into a file, database or
                cookie.
                >
                These functions are very PHP-specific, though some people have written
                functions to deal with PHP-style serialization in other languages. Of
                interest to you might be:
                >

                >
                In general though, I tend to recommend *against* rewriting code just
                because it's in a language you don't know. You may have a very good
                reason to be rewriting this website, but do consider whether a full
                rewrite is the best solution, or whether it might be better to learn
                some PHP and maintain the website that way. It's always a good idea
                to expand ones repetoire of skills.
                >
                --
                Toby A Inkster BSc (Hons) ARCS
                Contact Me ~ http://tobyinkster.co.uk/contact

                Comment

                Working...