setcookie($cookiename, $cookievalue, time() + (86400 * 30), "/"); // 86400 = 1 day
// PHP <7.0
if (isset($_COOKIE['user'])) {
// true, cookie is set
echo 'User is ' . $_COOKIE['user'];
else {
// false, cookie is not set
echo 'User is not logged in';
}
// PHP 7.0+
echo 'User is ' . $_COOKIE['user'] ?? 'User is not logged in';
//setcookie(name, value, expire, path, domain, security);
//understand first line and then implement the second one
setcookie($name, $value, 5, "/");
setcookie(
string $name,
string $value = "",
int $expires_or_options = 0,
string $path = "",
string $domain = "",
bool $secure = false,
bool $httponly = false
): bool