Jump to content

Archived

This topic is now archived and is closed to further replies.

martyng

Array to cookie to array

Recommended Posts

Hi
I'm trying to write a url id to an array then write this to a cookie, appending it to any previous entries. I'm struggling as i seem to just be storing one id and overwriting.

Please help

<?php
// get id from url
$setid = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['setid'] : addslashes($HTTP_GET_VARS['setid']);

if($_COOKIE["feature"]) {
// Convert the string back into an array.
$content = unserialize(stripslashes($_COOKIE["feature"]));
$content[] = $setid;
} else {
$content[] = $setid;
}
// write content to cookie as a string
setcookie("feature", addslashes(serialize($content)), time()+60*60*24*7);
$URL="./lightbox.php";header ("Location: $URL");
?>

Share this post


Link to post
Share on other sites
to append use the period in front of your equal sign.

$id = "55";
$id = "1";
// $id value is "1";

$var = "2";
$id.=$var;
// $id value is "12" -- retaining the "1" from previous code, and appending the "2".

let me know if this is not what you're looking for.

Share this post


Link to post
Share on other sites
[!--quoteo(post=351470:date=Mar 3 2006, 07:48 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Mar 3 2006, 07:48 PM) [snapback]351470[/snapback][/div][div class=\'quotemain\'][!--quotec--]
to append use the period in front of your equal sign.

$id = "55";
$id = "1";
// $id value is "1";

$var = "2";
$id.=$var;
// $id value is "12" -- retaining the "1" from previous code, and appending the "2".

let me know if this is not what you're looking for.
[/quote]

How would this relate to my array? i guess i need a , in there also as a seperator

Share this post


Link to post
Share on other sites
okay, I am not following the question.

you want $array[0] to equal the first value and $array[1] to equal the next, $array[2] the next, etc?

if that's what you're trying to do, you could:

$content[$i++] = unserialize(stripslashes($_COOKIE["feature"]));

better?

Share this post


Link to post
Share on other sites

×

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.