Jump to content

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");
?>
Link to comment
https://forums.phpfreaks.com/topic/4046-array-to-cookie-to-array/
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.
[!--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
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?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.