Read a Cookie in PHP

Read a cookie defensively

Cookies are client-controlled input. Check for the key and escape a value before putting it into HTML.

<?php
$value = $_COOKIE['Plus2netCookie'] ?? '';
if ($value !== '') {
    echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
?>
Cookie note: Secure cookies require HTTPS. Choose SameSite and HttpOnly settings according to how the cookie is actually used.

Current example first; the detailed tutorial examples below are retained for additional learning and comparison.



Welcome

Your name should appear after the welcome message above if cookie data is available.
echo "<b> Welcome </b><i>" .@$_COOKIE["Plus2netCookie"] . "</i>";
Start a new cookie cookies_t1.php | Check the cookie cookies_t2.php | Remove the cookie cookies_t3.php



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer