Store array in cookie










2














I am converting the array into cookie by php serialize function



$PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
"PromoteProductId"=>$PromoteProductId,
"PromoteBrandId"=>$PromoteBrandId);

$Promotedcart = $PromoteProductArray;

setcookie("Promotedcart", serialize($Promotedcart), time()+604800,'/');


And when the cookie is created then i am using the unserialize php function.



print_r(unserialize($_COOKIE['Promotedcart'])); 


it does not work.



When I print_R($_COOKIE) then it show me the value.










share|improve this question



















  • 1




    Test data can be very helpful, can you post sample
    – varela
    Sep 14 '11 at 10:02










  • See this StackOverflow question for a better answer.
    – Vera de Kok
    May 3 '13 at 14:18











  • Please do not use unserialize on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can use json_encode/json_decode instead of serialize/unserialize. owasp.org/index.php/PHP_Object_Injection
    – Quinn Comendant
    May 2 '14 at 23:53
















2














I am converting the array into cookie by php serialize function



$PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
"PromoteProductId"=>$PromoteProductId,
"PromoteBrandId"=>$PromoteBrandId);

$Promotedcart = $PromoteProductArray;

setcookie("Promotedcart", serialize($Promotedcart), time()+604800,'/');


And when the cookie is created then i am using the unserialize php function.



print_r(unserialize($_COOKIE['Promotedcart'])); 


it does not work.



When I print_R($_COOKIE) then it show me the value.










share|improve this question



















  • 1




    Test data can be very helpful, can you post sample
    – varela
    Sep 14 '11 at 10:02










  • See this StackOverflow question for a better answer.
    – Vera de Kok
    May 3 '13 at 14:18











  • Please do not use unserialize on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can use json_encode/json_decode instead of serialize/unserialize. owasp.org/index.php/PHP_Object_Injection
    – Quinn Comendant
    May 2 '14 at 23:53














2












2








2







I am converting the array into cookie by php serialize function



$PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
"PromoteProductId"=>$PromoteProductId,
"PromoteBrandId"=>$PromoteBrandId);

$Promotedcart = $PromoteProductArray;

setcookie("Promotedcart", serialize($Promotedcart), time()+604800,'/');


And when the cookie is created then i am using the unserialize php function.



print_r(unserialize($_COOKIE['Promotedcart'])); 


it does not work.



When I print_R($_COOKIE) then it show me the value.










share|improve this question















I am converting the array into cookie by php serialize function



$PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
"PromoteProductId"=>$PromoteProductId,
"PromoteBrandId"=>$PromoteBrandId);

$Promotedcart = $PromoteProductArray;

setcookie("Promotedcart", serialize($Promotedcart), time()+604800,'/');


And when the cookie is created then i am using the unserialize php function.



print_r(unserialize($_COOKIE['Promotedcart'])); 


it does not work.



When I print_R($_COOKIE) then it show me the value.







php arrays serialization cookies






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 '12 at 19:46









footy

2,84083990




2,84083990










asked Sep 14 '11 at 8:10









Amit

21137




21137







  • 1




    Test data can be very helpful, can you post sample
    – varela
    Sep 14 '11 at 10:02










  • See this StackOverflow question for a better answer.
    – Vera de Kok
    May 3 '13 at 14:18











  • Please do not use unserialize on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can use json_encode/json_decode instead of serialize/unserialize. owasp.org/index.php/PHP_Object_Injection
    – Quinn Comendant
    May 2 '14 at 23:53













  • 1




    Test data can be very helpful, can you post sample
    – varela
    Sep 14 '11 at 10:02










  • See this StackOverflow question for a better answer.
    – Vera de Kok
    May 3 '13 at 14:18











  • Please do not use unserialize on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can use json_encode/json_decode instead of serialize/unserialize. owasp.org/index.php/PHP_Object_Injection
    – Quinn Comendant
    May 2 '14 at 23:53








1




1




Test data can be very helpful, can you post sample
– varela
Sep 14 '11 at 10:02




Test data can be very helpful, can you post sample
– varela
Sep 14 '11 at 10:02












See this StackOverflow question for a better answer.
– Vera de Kok
May 3 '13 at 14:18





See this StackOverflow question for a better answer.
– Vera de Kok
May 3 '13 at 14:18













Please do not use unserialize on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can use json_encode/json_decode instead of serialize/unserialize. owasp.org/index.php/PHP_Object_Injection
– Quinn Comendant
May 2 '14 at 23:53





Please do not use unserialize on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can use json_encode/json_decode instead of serialize/unserialize. owasp.org/index.php/PHP_Object_Injection
– Quinn Comendant
May 2 '14 at 23:53













3 Answers
3






active

oldest

votes


















0














Cookies separated by semicolon. Serialized strings with arrays contain them inside. Maybe this is a problem. You can use base64 to avoid all possible escape issues.






share|improve this answer




















  • I tried base64 that also :( but no result
    – Amit
    Sep 14 '11 at 8:55


















0














Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php






share|improve this answer






























    0














    You can use json_encode, json_decode functions to achieve this as an alternative.



    $PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
    "PromoteProductId"=>$PromoteProductId,
    "PromoteBrandId"=>$PromoteBrandId);
    $Promotedcart = $PromoteProductArray;
    setcookie("Promotedcart", json_encode($Promotedcart), time()+604800,'/');
    $result = json_decode($_COOKIE['Promotedcart'], true);
    print_r($result);


    Give it a try, this should work.






    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7413161%2fstore-array-in-cookie%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Cookies separated by semicolon. Serialized strings with arrays contain them inside. Maybe this is a problem. You can use base64 to avoid all possible escape issues.






      share|improve this answer




















      • I tried base64 that also :( but no result
        – Amit
        Sep 14 '11 at 8:55















      0














      Cookies separated by semicolon. Serialized strings with arrays contain them inside. Maybe this is a problem. You can use base64 to avoid all possible escape issues.






      share|improve this answer




















      • I tried base64 that also :( but no result
        – Amit
        Sep 14 '11 at 8:55













      0












      0








      0






      Cookies separated by semicolon. Serialized strings with arrays contain them inside. Maybe this is a problem. You can use base64 to avoid all possible escape issues.






      share|improve this answer












      Cookies separated by semicolon. Serialized strings with arrays contain them inside. Maybe this is a problem. You can use base64 to avoid all possible escape issues.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Sep 14 '11 at 8:29









      varela

      9181714




      9181714











      • I tried base64 that also :( but no result
        – Amit
        Sep 14 '11 at 8:55
















      • I tried base64 that also :( but no result
        – Amit
        Sep 14 '11 at 8:55















      I tried base64 that also :( but no result
      – Amit
      Sep 14 '11 at 8:55




      I tried base64 that also :( but no result
      – Amit
      Sep 14 '11 at 8:55













      0














      Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php






      share|improve this answer



























        0














        Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php






        share|improve this answer

























          0












          0








          0






          Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php






          share|improve this answer














          Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 23 '17 at 11:47









          Community

          11




          11










          answered Dec 6 '11 at 22:46









          Smccullough

          198421




          198421





















              0














              You can use json_encode, json_decode functions to achieve this as an alternative.



              $PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
              "PromoteProductId"=>$PromoteProductId,
              "PromoteBrandId"=>$PromoteBrandId);
              $Promotedcart = $PromoteProductArray;
              setcookie("Promotedcart", json_encode($Promotedcart), time()+604800,'/');
              $result = json_decode($_COOKIE['Promotedcart'], true);
              print_r($result);


              Give it a try, this should work.






              share|improve this answer

























                0














                You can use json_encode, json_decode functions to achieve this as an alternative.



                $PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
                "PromoteProductId"=>$PromoteProductId,
                "PromoteBrandId"=>$PromoteBrandId);
                $Promotedcart = $PromoteProductArray;
                setcookie("Promotedcart", json_encode($Promotedcart), time()+604800,'/');
                $result = json_decode($_COOKIE['Promotedcart'], true);
                print_r($result);


                Give it a try, this should work.






                share|improve this answer























                  0












                  0








                  0






                  You can use json_encode, json_decode functions to achieve this as an alternative.



                  $PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
                  "PromoteProductId"=>$PromoteProductId,
                  "PromoteBrandId"=>$PromoteBrandId);
                  $Promotedcart = $PromoteProductArray;
                  setcookie("Promotedcart", json_encode($Promotedcart), time()+604800,'/');
                  $result = json_decode($_COOKIE['Promotedcart'], true);
                  print_r($result);


                  Give it a try, this should work.






                  share|improve this answer












                  You can use json_encode, json_decode functions to achieve this as an alternative.



                  $PromoteProductArray = array("PromoteuserId"=>$PromoteuserId,
                  "PromoteProductId"=>$PromoteProductId,
                  "PromoteBrandId"=>$PromoteBrandId);
                  $Promotedcart = $PromoteProductArray;
                  setcookie("Promotedcart", json_encode($Promotedcart), time()+604800,'/');
                  $result = json_decode($_COOKIE['Promotedcart'], true);
                  print_r($result);


                  Give it a try, this should work.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 3 '17 at 5:32









                  Rahul Meshram

                  6,49441839




                  6,49441839



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7413161%2fstore-array-in-cookie%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                      Museum of Modern and Contemporary Art of Trento and Rovereto