0

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.

A J
  • 161
  • 1
  • 1
  • 12
  • 1
    is index.php setting the cookie, possibly without regard for whether it was already set? where is the cookie set and with what params? – Joe T Nov 24 '13 at 00:43
  • Maybe you are setting cookie for 0 seconds? Or you are setting it on subfolder? Check this http://stackoverflow.com/a/612106/67332 – Glavić Nov 24 '13 at 00:46

1 Answers1

0

I've maneged to solve this problem.

I moved all cookie stuff from page.php to index.php and it's working!

I'm using Javascript for it, and there is no problem any more.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
A J
  • 161
  • 1
  • 1
  • 12