Search code examples
phpcookiessetcookie

php cookie with % in value


as php noob I have a problem with php setcookie. I try to achive a cookie which value is "bid_1%257C1544538505%257Ced2d154bb51e2a989fb30fe4250ce602" with php. This I tried so far... .

$cookieName = 'test';
$value =    'bid_1%7C1544538505%7Ced2d154bb51e2a989fb30fe4250ce602';
$setcookie($cookieName, $value, time()+3600); 

What I get is a cookie with a value of:

  bid_1%257C1544538505%257Ced2d154bb51e2a989fb30fe4250ce602

How can I achive a correct value and prevent php from transforming "%". Many Thanks in advance.

I tried without success

 $value =    'bid_1%%7C1544538505%%7Ced2d154bb51e2a989fb30fe4250ce602';// and
 $value =    'bid_1\%7C1544538505\%7Ced2d154bb51e2a989fb30fe4250ce602';

Solution

  • Basically the root problem is that setcookie encodes your value, therefore some characters like % are encoded as %25

    Solution

    setrawcookie doesn't have this feature and therefore returns the result you want