Store array in cookie
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
add a comment |
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
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 useunserialize
on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can usejson_encode/json_decode
instead ofserialize/unserialize
. owasp.org/index.php/PHP_Object_Injection
– Quinn Comendant
May 2 '14 at 23:53
add a comment |
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
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
php arrays serialization cookies
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 useunserialize
on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can usejson_encode/json_decode
instead ofserialize/unserialize
. owasp.org/index.php/PHP_Object_Injection
– Quinn Comendant
May 2 '14 at 23:53
add a comment |
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 useunserialize
on user-submitted data. This is easily exploitable with object injection using PHP's __wakeup and __destruct methods. You can usejson_encode/json_decode
instead ofserialize/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
add a comment |
3 Answers
3
active
oldest
votes
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.
I tried base64 that also :( but no result
– Amit
Sep 14 '11 at 8:55
add a comment |
Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
I tried base64 that also :( but no result
– Amit
Sep 14 '11 at 8:55
add a comment |
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.
I tried base64 that also :( but no result
– Amit
Sep 14 '11 at 8:55
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php
add a comment |
Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php
add a comment |
Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php
Just ran into a situation where I also needed to use this solution. I found my answer here: update cookie value in php
edited May 23 '17 at 11:47
Community♦
11
11
answered Dec 6 '11 at 22:46
Smccullough
198421
198421
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 3 '17 at 5:32
Rahul Meshram
6,49441839
6,49441839
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 usejson_encode/json_decode
instead ofserialize/unserialize
. owasp.org/index.php/PHP_Object_Injection– Quinn Comendant
May 2 '14 at 23:53