Organizational Research By

Surprising Reserch Topic

how to calculate Cookie Size in PHP


I wanted to read the cookie and calculate its length on server side using php, but can't find any direct method to do so. So how to achieve this task ?


asked May 28, 2015 in PHP by rajesh
0 votes
36 views



Related Hot Questions

2 Answers

0 votes
setcookie("user", "boostr", time() + 3600);

if (isset($_COOKIE["user"])) { $data = $_COOKIE["user"]; $serialized_data = serialize($data); $size = strlen($serialized_data); echo 'Length : ' . strlen($data); echo "
"; echo 'Size : ' . ($size * 8 / 1024) . ' Kb'; }

// Output

Length : 21 Size : 0.232 Kb
answered May 28, 2015 by rajesh
edited May 29, 2015 by rajesh
0 votes

To get the raw cookies and their length:

$rawCookies = isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : null;
$rawLength  = strlen($rawCookies);
echo $rawLength;
answered May 28, 2015 by rajesh

...