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
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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

thats why I said they can BE arrays...

 

array.split() is the js equivalent of explode.

 

My personal opinion is not use javascript for setting cookies - let the server do it - you don't need to worry if js is activated or not then.

Link to comment
Share on other sites

you can like this.

 

if you know its a 2-d array...

 

<?php
foreach($_POST[index1] as $outerkey => $arr)
{
foreach($arr as $innnerkey => $val)
{
  setcookie('cookie[' . $outerkey . '][' . $innerkey . ']', $val);
}
}
?>

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

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.