PC Nerd Posted May 1, 2007 Share Posted May 1, 2007 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 Quote Link to comment Share on other sites More sharing options...
taith Posted May 1, 2007 Share Posted May 1, 2007 a) thats javascript... not php... b) no, cookie cannot hold arrays... Quote Link to comment Share on other sites More sharing options...
DaveEverFade Posted May 1, 2007 Share Posted May 1, 2007 Cookies can hold arrays, i've done it before (by accident). Although I don't know how to do that in javascript! Quote Link to comment Share on other sites More sharing options...
taith Posted May 1, 2007 Share Posted May 1, 2007 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. Quote Link to comment Share on other sites More sharing options...
DaveEverFade Posted May 1, 2007 Share Posted May 1, 2007 Sorry, just tested, you are right... I must have been thinking about somthing else.. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted May 1, 2007 Author Share Posted May 1, 2007 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? Quote Link to comment Share on other sites More sharing options...
jitesh Posted May 1, 2007 Share Posted May 1, 2007 From HTML you can use javascript to create a cookie. In case of array it is possible Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted May 1, 2007 Author Share Posted May 1, 2007 can i create a multi dimensional array cookie, or POST, or GET? direct from the form? how would i go about deoing this cookie? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 1, 2007 Share Posted May 1, 2007 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... Quote Link to comment Share on other sites More sharing options...
taith Posted May 1, 2007 Share Posted May 1, 2007 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... Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 1, 2007 Share Posted May 1, 2007 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. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted May 1, 2007 Author Share Posted May 1, 2007 ok, so i cant do my idea, having the cookie holding arrays..... can POST or GET hold arrays, eg: $_POST[index1][index2] ? thanks Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 1, 2007 Share Posted May 1, 2007 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); } } ?> Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted May 1, 2007 Author Share Posted May 1, 2007 but i need to create the multidimensional thing, whether its cookie, POST or whatever.... how do i do it? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 1, 2007 Share Posted May 1, 2007 I just have!!!!!!!! that code creates a multi dimensional cookie after that you can call the elements of the cookie as normal Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted May 1, 2007 Author Share Posted May 1, 2007 i understand this is the wrong section, but how would i do that in javascript? i want it to all be done on the one page. Quote Link to comment Share on other sites More sharing options...
taith Posted May 1, 2007 Share Posted May 1, 2007 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 ... i included the explode there too if you want to go backwards :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.