Jump to content

multi dimensional cookies


PC Nerd

Recommended Posts

firstly, can i create a cookie, drectly from a hmtl form?

 

 

is it possible to have a multi domensional cookie, ie:

 

cookie = documdnt.cookie

 

cookie[index1][index2] etc.

 

 

can i do this?

 

if not, how would i have something like that?, can i make POST datab or GET data like this?

 

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/
Share on other sites

so how would i do this.....

 

i have 10 forms, and i need each form to become an array ( its fields the arrays elements...)

 

i dont really mind if its POST data, or simply a cookie, and can i do this directly from the form eg method = '' action = '' etc/.

 

 

thanks?

cookies can BE arrays.....

 

http://uk3.php.net/manual/en/function.setcookie.php#id5573620

 

no... cookies cannot hold arrays... now if one were to serialize/implode the array, sure it'd work... but its not an array then... its a string.

serializing an array produces a string - unserializing a string that was formed from an array will produce an array...

i didnt say cookies couldnt be arrays... i said they couldnt hold arrays...

 

$array=array("asfd","1");
setcookie("array",$array);

only  gives errors...

 

now... for javascript... you can turn arrays into strings like so...

function implode(array,seperator){ 
return array.join(seperator);
}

 

personally... i havent found a way of exploding yet...

forgive me, javascript is not my first language... some of this probably will be wrong... lol

 

and just to make things php consistant...

<s cript>
function implode(seperator,array){
return array.join(seperator);
}
function explode(seperator,array){
return array.split(seperator);
}

var string=implode('|',array);
</s cript>

then you just need to set the string, to the cookie :D... i included the explode there too if you want to go backwards :-)

Archived

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

×
×
  • 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.