Jump to content

PHP cookie reading


opencombatclan

Recommended Posts

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

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

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

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

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

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.