opencombatclan Posted July 17, 2008 Share Posted July 17, 2008 I have a question. I have a cookie called "sc1". The cookie contains the following data: 1|1|4|67|28|8|1000|2000|0|0|0|0|0|0|0|0|2000|1000|0|0|0|0|0|0|0|-1|0|0|0|67|67|1866|866|0|0|0| As you can see those are values separated by "|" Now I have to tell my php script that variable "Width : "First value of cookie" How can i do this? I really need to split the cookie values in php variables... I hope you can help me out! Yours faithfully, steven Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/ Share on other sites More sharing options...
unkwntech Posted July 17, 2008 Share Posted July 17, 2008 //cookie value stored as $data $data = split('/\|/', $data); $width = data['0']; PHP's split() will 'split' a string into an array based on a regex of the delimitor, in this case | (regex: '/\|/') See http://www.php.net/split for more info Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592314 Share on other sites More sharing options...
opencombatclan Posted July 17, 2008 Author Share Posted July 17, 2008 Thanks for fast answer! I will try now.. You will hear if it worked for me. Ur my hero Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592317 Share on other sites More sharing options...
opencombatclan Posted July 17, 2008 Author Share Posted July 17, 2008 //cookie value stored as $data $data = split('/\|/', $data); $width = data['0']; PHP's split() will 'split' a string into an array based on a regex of the delimitor, in this case | (regex: '/\|/') See http://www.php.net/split for more info I am a bit newby with php... Do i have to use: $cookie = $_COOKIE["sc1"] Or don't I have to use that? I have to tell php it has to split from cookie, isn't it? Where do i tell php that $data has splitted values of cookie? Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592324 Share on other sites More sharing options...
unkwntech Posted July 17, 2008 Share Posted July 17, 2008 $data = split('/\|/', $_COOKIE["sc1"]); $width = data['0']; Would be perfect.... Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592326 Share on other sites More sharing options...
opencombatclan Posted July 17, 2008 Author Share Posted July 17, 2008 Or does it has to be: $cookie = $_COOKIE["sc1"]; $data = split('/\|/', $cookie); $width = data['0']; Is this correct??? I see at the moment i was writing this, Someone else says the same... So i assume its correct Thanks all for helping Extremely FAST! Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592330 Share on other sites More sharing options...
opencombatclan Posted July 17, 2008 Author Share Posted July 17, 2008 <?php $data = split('/\|/', $_COOKIE["sc1"]); $scc = data['0']; $p = data['1']; $s = data['2']; $d = data['3']; $rd = data['4']; $sp = data['5']; $h = data['6']; $b = data['7']; $hout = data['8']; $k_a = data['9']; $k_po = data['10']; $k_pb = data['11']; $k_pl = data['12']; $k_pr = data['13']; ?> This i have now... but when i visit site (i expect to see empty screen) i see Parse error: syntax error, unexpected '[' in /srv/www/vhosts/*site*/httpdocs/*directory*/showdata.php on line 3 Why is it giving error? Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592339 Share on other sites More sharing options...
opencombatclan Posted July 17, 2008 Author Share Posted July 17, 2008 I found problem was "$" i now have <?php $data = split('/\|/', $_COOKIE["sc1"]); $scc = $data['0']; $p = $data['1']; $s = $data['2']; $d = $data['3']; $rd = $data['4']; $sp = $data['5']; $h = $data['6']; $b = $data['7']; $hout = $data['8']; $k_a = $data['9']; $k_po = $data['10']; $k_pb = $data['11']; $k_pl = $data['12']; $k_pr = $data['13']; echo $p; echo $data[1]; ?> I expext to see 2 values on my screen now... But its empty, No error, no values... So whats going wrong this time????? Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592343 Share on other sites More sharing options...
opencombatclan Posted July 17, 2008 Author Share Posted July 17, 2008 <?php list($scc,$p,$s,$d,$rd,$sp,$h,$b,$hout,$k_a,$k_po,$k_pb,$k_pl,$k_pr) = explode('|',$_COOKIE["sc1"]); echo $p; ?> That fixed it for me... Thanks to the answer by a moderator... I don't know why my previous option did not work, bu i do know that this works! Topic can be closed, its solved now. Link to comment https://forums.phpfreaks.com/topic/115194-php-cookie-reading/#findComment-592377 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.