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 Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/ 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... Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242164 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! Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242165 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. Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242166 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.. Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242168 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? Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242182 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 Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242185 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? Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242206 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... Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242210 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... Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242212 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. Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242214 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 Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242230 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); } } ?> Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242233 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? Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242248 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 Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242281 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. Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242299 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 :-) Link to comment https://forums.phpfreaks.com/topic/49418-multi-dimensional-cookies/#findComment-242344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.