Setcookie does not work php

I want to set a cookie whose value comes from a variable and does not work (this is not a page translation). Here is my code:

$store_view_aw=array();
$store_view_aw=explode('/',$_SERVER['REQUEST_URI']);
$store_view=trim($store_view_aw[2]);
setcookie("googtrans", "", time()-3600,'/','');
setcookie("googtrans", "", time()-3600,'/','.domain.com');
if($store_view=='es'){
 setcookie("googtrans","/en/es", time()+3600, "/",'.domain.com');
}

But if on line number 3 I use some kind of static value, then it works (i.e. translates the page) ex:

$store_view='es';

I printed my data type, also using var_dump (), it is the same for both static and dynamic variable. I also tried using ob_start () and ob_end_flush (); but that didn't work either. I am completely stuck here, please help. Thanks in advance.

+4
source share
1 answer

Try the following:

 setcookie ( "googtrans" , "/en/es" , time ()+ 3600 ,  "/"); 
0
source

Source: https://habr.com/ru/post/1606770/


All Articles