I'm using PHP 7.2.0
I want to omit the expire parameter in setcookie()
function while setting the cookie, so I tried below code and got Parse error in output.
<!DOCTYPE html>
<?php
$cookie_n = "user";
$cookie_value = "John Doe";
setcookie($cookie_n, $cookie_value, , "/");
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_n])) {
echo "Cookie named '" . $cookie_n . "' is not set!";
} else {
echo "Cookie '" . $cookie_n . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_n];
}
?>
<p><strong>Note:</strong> You might have to reload the page to see the value of the cookie.</p>
</body>
</html>
Output : Parse error: syntax error, unexpected ',' in ... on line 5
Then I tried with below setcookie()
code but I got Warning and the cookie didn't get set:
setcookie($cookie_n, $cookie_value, '' , "/");
Output :
Warning: setcookie() expects parameter 3 to be integer, string given in ... on line 5
Cookie named 'user' is not set!
Note: You might have to reload the page to see the value of the cookie.
From manual consider below text about expire parameter,
If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
So, according to this I tried the code but it's not working and generating parse error and notice. Please someone help me and correct the mistake I'm making in my code.
I also want to know, whether the cookie value set by omitting expire parameter value will be alive after closing the respective browser tab only and not the entire web browser?
Can I set cookies from Command Line? If yes, how? If no, why?
Thank You.