Welcome! Log In Create A New Profile

Advanced

[PHP] cookies not remembered between browser shutdown and browser restart.. :(

Posted by Rene Veerman 
i have the following test script:
<html>
<body>
<?php var_dump($_COOKIE);?>
<script>
document.write (document.cookie);
document.cookie = 'abc=def';
</script>
</body>
</html>

if you load it up, you get an empty page.
if you then refresh the page, you get that abc cookie displayed.

but if you close down the browser entirely and restart it, then view the
script output again, it doesn't show the cookie that was set earlier.

what am i doing wrong here?

because this used to work just fine, then it suddenly stopped working in
both firefox and chrome.
i'm using ubuntu and lubuntu.
> On Mar 27, 2018, at 2:18 AM, Rene Veerman <[email protected]> wrote:
>
> i have the following test script:
> <html>
> <body>
> <?php var_dump($_COOKIE);?>
> <script>
> document.write (document.cookie);
> document.cookie = 'abc=def';
> </script>
> </body>
> </html>
>
> if you load it up, you get an empty page.
> if you then refresh the page, you get that abc cookie displayed.
>
> but if you close down the browser entirely and restart it, then view the
> script output again, it doesn't show the cookie that was set earlier.
>
> what am i doing wrong here?
>
> because this used to work just fine, then it suddenly stopped working in
> both firefox and chrome.
> i'm using ubuntu and lubuntu.

The first thing I would check is if the browser prefs have been set to dump cookies
when it quits.

In the Firefox I am using, under Privacy in Preferences, there is a checkbox:
Accept from sites, and below that a sub option "Keep Until": <select/option>
I have chosen "I close Firefox" from the selection list.

I am using Firefox 54.0.1 (64-bit) on Mac OSX.

The ttl of the cookie might not be set long enough during the time the browser is
opened.

That is all I can thing of.

Best;
JK


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Good morning,

Am 2018-03-27 hackte Rene Veerman in die Tasten:
> i have the following test script:
> <html>
> <body>
> <?php var_dump($_COOKIE);?>
> <script>
> document.write (document.cookie);
> document.cookie = 'abc=def';
> </script>
> </body>
> </html>

I have codede JS 15 years ago and do not know about todays stuff,
but can it be, that it is only a session cookie?

Thanks in advance

--
Michelle Konzack Miila ITSystems @ TDnet
GNU/Linux Developer 00372-54541400


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
> On Mar 27, 2018, at 7:57 PM, Michelle Konzack <[email protected]> wrote:
>
> Good morning,
>
> Am 2018-03-27 hackte Rene Veerman in die Tasten:
>> i have the following test script:
>> <html>
>> <body>
>> <?php var_dump($_COOKIE);?>
>> <script>
>> document.write (document.cookie);
>> document.cookie = 'abc=def';
>> </script>
>> </body>
>> </html>
>
> I have codede JS 15 years ago and do not know about todays stuff,
> but can it be, that it is only a session cookie?
>
> Thanks in advance
>

It depends on what set the cookie to begin with.

If it was php, it is either a call to setCookie, or a session cookie.
I don't work with cookies accept for limited specific tasks. But
in calling setCookie one of the arguments is the time to live value.
If there is no time to live value passed, the cookie expires when
the browser closes... as I understand it. Look at the php manual:

http://php.net/manual/en/function.setcookie.php (or find it in your
preferred language, this the english version. You can use the search
box at the upper right hand corner. But it may be different for languages
written and read right to left)

Javascript should have nothing to do with it unless there is javascript
code sourced and run in the browser to effect cookies. They can be
set and remove or changed with javascript. But it is more complicated
than php. The cookies are read as a string and have to be parsed
and analysed by javascript and added to, removed or revised.

JK
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Hello Jeffry,

Am 2018-03-28 hackte Jeffry Killen in die Tasten:
>> On Mar 27, 2018, at 7:57 PM, Michelle Konzack
>> <[email protected]> wrote:
>> Am 2018-03-27 hackte Rene Veerman in die Tasten:
>>> <html>
>>> <body>
>>> <?php var_dump($_COOKIE);?>
>>> <script>
>>> document.write (document.cookie);
>>> document.cookie = 'abc=def';
>>> </script>
>>> </body>
>>> </html>

> It depends on what set the cookie to begin with.

Please look at the code of the OP.
He set the cookie from the JavaScript and NOT PHP.

He is just reading the value of the cookie using PHP.

> If it was php, it is either a call to setCookie, or a session cookie.
> I don't work with cookies accept for limited specific tasks. But
> in calling setCookie one of the arguments is the time to live value.
> If there is no time to live value passed, the cookie expires when
> the browser closes... as I understand it. Look at the php manual:
>
> http://php.net/manual/en/function.setcookie.php (or find it in your
> preferred language, this the english version. You can use the search
> box at the upper right hand corner. But it may be different for
> languages
> written and read right to left)

I do not nee this infos, because I code PHP since some time!

> Javascript should have nothing to do with it unless there is
> javascript
> code sourced and run in the browser to effect cookies.

Please loock at the code again!

> They can be
> set and remove or changed with javascript. But it is more complicated
> than php. The cookies are read as a string and have to be parsed
> and analysed by javascript and added to, removed or revised.
>
> JK

Have a nice day

--
Michelle Konzack Miila ITSystems @ TDnet
GNU/Linux Developer 00372-54541400


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
figured it out.. the cookie needs a valid expires setting and a valid path
setting. not a domain setting.

this is easy to do using the jQuery cookie plug in, look on the web for the
plain-vanilla syntax please.

On Tue, Mar 27, 2018 at 11:18 AM, Rene Veerman <
[email protected]> wrote:

> i have the following test script:
> <html>
> <body>
> <?php var_dump($_COOKIE);?>
> <script>
> document.write (document.cookie);
> document.cookie = 'abc=def';
> </script>
> </body>
> </html>
>
> if you load it up, you get an empty page.
> if you then refresh the page, you get that abc cookie displayed.
>
> but if you close down the browser entirely and restart it, then view the
> script output again, it doesn't show the cookie that was set earlier.
>
> what am i doing wrong here?
>
> because this used to work just fine, then it suddenly stopped working in
> both firefox and chrome.
> i'm using ubuntu and lubuntu.
>
>
>
>
Sorry, only registered users may post in this forum.

Click here to login