xxxxxxxxxx
// SYNTAX
//setcookie(name, value, expire, path, domain, secure, httponly);
$cookie_name = "LoginUser";
$cookie_value = "ex@gmail.com";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
// FOR UNSET COOCKIE
unset($_COOKIE['LoginUser']);
xxxxxxxxxx
<?php
$expireDate = time()+2*24*60*60;
setcookie("Auction_Item", "Luxury Car", $expireDate);
?>
Cookie() method will take 3 arguments. 3 arguments. First argument is the name of the cookie, second argument is the value of the cookie and the third argument is the duration of the cookie after which the cookie will get deleted automatically.
xxxxxxxxxx
//Create a response instance
$response = new Illuminate\Http\Response('Hello World');
//Call the withCookie() method with the response method
$response->withCookie(cookie('name', 'value', $minutes));
//return the response
return $response;