1

I am facing problem with setcookie(), its working fine on localhost but not on Server, this issue happened when I changed Unicode for all my webpages and database to utf-8. the following is snippet of my code:

if(isset($_GET['langid'])) { 
        $langID = $_GET['langid']; 
        setcookie('langid', $langID); 
    } 
    elseif  (isset($_COOKIE['langid'])) {
        $langID = $_COOKIE['langid']; 
        echo $_COOKIE['langid'];
    }
    else {
        $langActive=mysql_query("SELECT * FROM languages WHERE id=2 AND active=2");
        $langActive=mysql_fetch_array($langActive);
            if (empty($langActive)){ $langID = 0;}
            else{ $langID = 2; }
}
hani
  • 11
  • 1
  • what var_dump of setcookie returns on the server? – krasipenkov Nov 08 '16 at 09:13
  • Please specify "is not working". Have you enabled error reporting? Maybe you are facing a "headers already sent" error. This is typically for the UTF-8 Byte Order Mark: https://en.wikipedia.org/wiki/Byte_order_mark. – secelite Nov 08 '16 at 09:16
  • I'm not sure but a php.ini with different configuration (which could be possible on shared servers) can make the problem too ! – Sinf Nov 08 '16 at 09:22
  • result of var_dump: 1. 1st time: string(2) "10" // no. of lang 2. second time : int(2) – hani Nov 08 '16 at 11:18
  • see this http://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain – Archish Nov 08 '16 at 11:24

0 Answers0