O
O
Outsider V.2015-02-16 22:57:00
PHP
Outsider V., 2015-02-16 22:57:00

Why cookies are deleted only the second time?

I'm sawing a user module on the site. When entering through the form, if the user is found, his data is loaded into the session, and if "remember me" is checked, part of the data is also written to Cookies. Then, if there is no session, the engine tries to find this cookie and log in through it.
The problem is this: all browsers on Windows work fine with logging in / out, but for some reason the Android browser - UC Browser - for some reason does not want to delete the session or delete the Cookie at the first click on the Logout button. On the second click, everything is deleted (between two clicks, there may even be transitions through the pages of the site, or even closing the browser).
How can this be??
Here is the code for deleting cookies:

if(isset($_GET['logout'])) // Logout if there was such command
{
session_destroy();
setcookie('userdata', '', time()-3600);
header("Location: $ref"); // Go to entry page
exit;
}

(That is, the idea is that when requesting the address /login.php?logout, both the session and cookies are deleted, after which it is redirected to the page from which the logout was requested)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim, 2015-02-16
@maxloyko

if you deleted the session and you are checking the corresponding one in the code, then I can safely assume that the browser goes through the cache, and why it does not delete the cookie, mb bug what xs.

A
Alexey Nikolaev, 2015-02-16
@Heian

Most likely, in the first case, a notice or warning level error is thrown that you do not see. Well, or any other header is sent. setcookie must be called before any headers.

O
Outsider V., 2015-02-17
@Audiophile

All of a sudden, everything was solved by deleting the session Cookie via setcookie 'PHPSESSID".
Now I'm sitting thinking why normal browsers work without it, but UC doesn't.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question