从cookie中的“DEFINE”设置值[关闭]

i tried to set value from "DEFINE" in cookie.

define("DEFUALT_LANG", "EN");

if(!isset($_COOKIE['user_lang'])) 
    setcookie("user_lang", DEFUALT_LANG, time()+3600*24*365); 

echo "lang:".$_COOKIE['user_lang'];

print is: DEFUALT_LANG

a little weird, no? it supposed to be "EN"...

You can use constant($string) to get define value.

http://php.net/manual/fr/function.constant.php

setcookie("user_lang", constant("DEFUALT_LANG"), time()+3600*24*365);

Replace You code with this:

define("DEFUALT_LANG", "EN");

if(!isset($_COOKIE['user_lang'])) 
    setcookie("user_lang", constant(DEFUALT_LANG), time()+3600*24*365); 

echo "lang:".$_COOKIE['user_lang'];