mercredi 1 juin 2016

Cookies disappear when visiting index.php

I use some cookies to set the App::setLocale($cookievalue); website's language in laravel. Though everytime I visit my homepage (page where i can simply choose language), my cookie disappears from the list. While on every other page it is right there

I can't seem to understand why, since I only destroy the session variable and don't unset the cookies.

testing fase, once done it will allow users to choose to remember or not

So here is the php header for the index.php file:

if (session_status() == PHP_SESSION_NONE) {

 } else {
     session_destroy();
 }
 if(count($_COOKIE) > 0) {
     if (isset($_COOKIE['language'])) {
         return redirect('/home');
     }
 }

All I do on the other pages is check wether the cookie "language" is set, and if so , set the App's locale to its value, like this :

if (isset($_COOKIE['language'])) {
    $lang = $_COOKIE['language'];
    App::setLocale($lang);
}

And this is the controller's function for when I go to index.php :

    public function setLocale($country) {
         App::setLocale($country);
         $uri = Input::get('hrURI');
         if ( isset($uri)) {
             return redirect(Input::get('hrURI'))->with('lang', [$country]);
         }
         else {
             return redirect('/home')->with('lang', [$country]);
         }
     }

And here you can see that the cookie is vivisble on the about page (for example) Cookie is present !

But then on the index.php page its gone, is laravel unsetting it ? is this default ? I can't find my answer on google so I'm trying here, sorry if I'm asking a stupid / obvious question, i just don't see it.

The site is live online @ http://ift.tt/1sLNIO1 So you can see the website if you wanna see everything for yourself



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire