Jump to content


Photo

Array to cookie to array


  • Please log in to reply
3 replies to this topic

#1 martyng

martyng
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 03 March 2006 - 11:28 PM

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");
?>

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 04 March 2006 - 12:48 AM

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.

#3 martyng

martyng
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 04 March 2006 - 01:44 AM

[!--quoteo(post=351470:date=Mar 3 2006, 07:48 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Mar 3 2006, 07:48 PM) View Post[/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

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 04 March 2006 - 02:09 AM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users