spiderman
spiderman

Reputation: 1417

How to set comma separated values in cookies

when i try to set cookie in the following way the values show me in the browser for the cookies are like this cookie name -> recent and value 1%2c2 where 1 and 2 are my get parameters and %2c i dont know what is this i wants , in place of %2c

if(!empty($_GET['c']))
{
    $c = $_GET['c'];
    if(isset($_COOKIE['recent']))
    {
        $c=$_COOKIE['recent'].','.$c;
        setcookie('recent',$c);
    }
    else
    {
        if(setcookie('recent',$c))
        {
            echo "yes";
        }
        else
        {
            echo "no";
        }
    }
}
echo $_COOKIE['recent'];

Upvotes: 0

Views: 3698

Answers (1)

Electronick
Electronick

Reputation: 1122

Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name.

http://php.net/manual/en/function.setcookie.php

http://www.php.net/manual/ru/function.urlencode.php

Upvotes: 6

Related Questions