martyng Posted March 3, 2006 Share Posted March 3, 2006 HiI'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 stringsetcookie("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 More sharing options...
michaellunsford Posted March 4, 2006 Share Posted March 4, 2006 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. Link to comment https://forums.phpfreaks.com/topic/4046-array-to-cookie-to-array/#findComment-14041 Share on other sites More sharing options...
martyng Posted March 4, 2006 Author Share Posted March 4, 2006 [!--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 Link to comment https://forums.phpfreaks.com/topic/4046-array-to-cookie-to-array/#findComment-14053 Share on other sites More sharing options...
michaellunsford Posted March 4, 2006 Share Posted March 4, 2006 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? Link to comment https://forums.phpfreaks.com/topic/4046-array-to-cookie-to-array/#findComment-14057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.