// Set a cookie with a value that expires in 1 hour setcookie('username', 'john', time() + 3600); // Set a secure cookie that can only be accessed over HTTPS setcookie('session_id', '123', time() + 3600, '/', 'example.com', true, true);
// Get the value of the 'username' cookie $username = isset($_COOKIE['username']) ? $_COOKIE['username'] : ''; echo "Hello, $username!";The PHP Cookie functionality is built-in as part of the PHP core, so no external package library is required.