I'm programming a web app. So I have index.php where i check if cookie exsist, if there is no cookie input box would be filled with "test" else with cookie's value. Then i have a button to post this input value to page.php, there i do some work. But at the end of this page.php is
<button onclick="location.href = 'index.php';"
class="float-left submit-button">Back</button>
If i stay at this page.php and close browser, when I reopen it the cookie will be still here, but if I click on this button to navigate back to index.php the cookie is lost in a sec
This part is in index.php for checking whether cookie exsist or not:
<?php
if (isset($_COOKIE["A"]))
{
echo $_COOKIE["A"];
}
else
{
echo "test";
}
?>
And this part set the cookie in page.php
if (isset($_COOKIE["A"]))
{
unset($_COOKIE['A']);
setcookie('A', '', time() - 3600);
}
$domain = $_SERVER["HTTP_HOST"];
setcookie("A", $value,time()+ 86400 * 365,"/",$domain,false,true);
And cookie is set only in Firefox, on Chrome it's not working at all.