V
V
Vasily2016-10-24 00:32:15
PHP
Vasily, 2016-10-24 00:32:15

Why does location.reload remove cookies?

When reloading the page using the JS method: location.reload(false), cookies are deleted.
Here is my php code:

<?php
require_once("php/lib/streams.php");
require_once("php/lib/gettext.php");
$setup_lang = locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']);
// $selected_lang = array("pl_PL","en_US");
// $locale_lang = in_array($locale_lang, $selected_lang) ?  $locale_lang : "en_US";
if(isset($_POST['lang'])){
    $locale_lang = $_POST['lang'];
    setcookie("your_lang", $locale_lang, time() + (86400 * 3), "/");
     $locale_file = new FileReader("php/locale/" . $_COOKIE["your_lang"] . "/LC_MESSAGES/messages.mo");
}
else if(!isset($_COOKIE["your_lang"]))
{
    $locale_file = new FileReader("php/locale/" . $setup_lang . "/LC_MESSAGES/messages.mo");
}else{
    $locale_file = new FileReader("php/locale/" . $_COOKIE["your_lang"] . "/LC_MESSAGES/messages.mo");
}



$locale_fetch = new gettext_reader($locale_file);

function __($text){
  global $locale_fetch;
  return $locale_fetch->translate($text);
}

 ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2016-10-24
@taliban

Are you sure it's the cookies? Are you deleting cookies, or is the language set not what you expect from cookies?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question