Read an Array-Style Cookie in PHP
PHP Tutorials PHP Sessions PHP Cookies Read Cookie Array Read expected keys from the cookie array Check both the parent cookie array and the individual keys you need.
<?php
$cookie = $_COOKIE ['Plus2netCookie' ] ? ? [];
$name = is_array ($cookie ) ? ($cookie ['name' ] ? ? '' ) : '' ;
if ($name !== '' ) {
echo htmlspecialchars ($name , ENT_QUOTES , 'UTF-8' );
}
?> Cookie settings: Use Secure on HTTPS sites, HttpOnly when JavaScript does not need the cookie, and choose SameSite according to the cross-site behavior your application requires.
No cookie is set.
if (isset ($_COOKIE ['Plus2netCookie' ])){
echo "<div class='alert alert-info'>
<div class='row'> <div class='col-md-4'> <b>Name</b> </div><div class='col-md-4'>" . $_COOKIE ['Plus2netCookie' ]['name' ]. "</div></div>
<div class='row'> <div class='col-md-4'> <b>City</b> </div><div class='col-md-4'>" . $_COOKIE ['Plus2netCookie' ]['city' ]. "</div></div>
<div class='row'> <div class='col-md-4'> <b>State</b> </div><div class='col-md-4'>" . $_COOKIE ['Plus2netCookie' ]['state' ]. "</div></div>
<div class='row'> <div class='col-md-4'> <b>Zip</b> </div><div class='col-md-4'>" . $_COOKIE ['Plus2netCookie' ]['zip' ]. "</div></div>
</div><br><br><div class='alert alert-warning'>" ;
print_r ($_COOKIE ['Plus2netCookie' ]);
echo "</div>" ;
}else {
echo " No Cookie is set " ;
}
Author & Instructor at
plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery,
and web development at plus2net. The tutorials focus on clear explanations, working
examples, and code that readers can test and adapt while learning.
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com
✖
We use cookies to improve your browsing experience. . Learn more