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 ?
what about this ?
setcookie("user", "Dino babu kannampuzha", time() + 3600);
if (isset($_COOKIE["user"])) {
$data = $_COOKIE["user"];
$serialized_data = serialize($data);
$size = strlen($serialized_data);
echo 'Length : ' . strlen($data);
echo "<br/>";
echo 'Size : ' . ($size * 8 / 1024) . ' Kb';
}
// Output
Length : 21
Size : 0.232 Kb
To get the raw cookies and their length:
$rawCookies = isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : null;
$rawLength = strlen($rawCookies);
echo $rawLength;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With