S
S
Sergey Pugovkin2018-07-29 14:47:28
PHP
Sergey Pugovkin, 2018-07-29 14:47:28

Why does Google Chrome Android do two redirects instead of one on a POST request?

<?php
if (!empty($_POST['text'])) {
    header('Location: /test.php');
    setcookie('testCookie', '1', time() + 3600, '/');
    exit();
}
setcookie('testCookie', '0', time() + 3600, '/');
?><form action="" method="post">
    <input name="text" type="text" value="text">
    <button type="submit">submit</button>
</form>
testCookie: <?= $_COOKIE['testCookie'] ?? 'null'  ?>

Code logic: we submit the form, pass the cookie to the browser, the page is refreshed (via a redirect) and the contents of the cookie are displayed ("testCookie: 1").
But the behavior in Google Chrome Android is different. Instead of "testCookie: 1", it displays "testCookie: 0".
Reason: judging by the logs, this browser accesses the page more than twice: first by submitting the form, then receiving a redirect, and a third time to the same page (following the redirect). Although the Google Chrome Android console shows only two requests.
In incognito mode, there is no such "feature" and everything is as it should be. Also, if you redirect to another page, for example /test.php?123456789 - everything is fine too.
What is it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pugovkin, 2018-08-18
@Driver86

In general, as it turned out, Maxim Fedorov is right: this is some kind of cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question