A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearPHP: getting a “use of undefined constant COOKIE_LOGIN” how do I fix this? - page 1
User InfoPosts
PHP: getting a “use of undefined constant COOKIE_LOGIN” how do I fix this?#1
I haven(t made any changes to the code affecting the COOKIE(s and now I get the following:

Use of undefined constant COOKIE_LOGIN - assumed (COOKIE_LOGIN(

//Destroy Cookie
if (isset($_COOKIE[COOKIE_LOGIN]) && !empty($_COOKIE[COOKIE_LOGIN]))
setcookie(COOKIE_LOGIN,$objUserSerialized,time() - 86400 );


I(m not sure what I need to do to actually change this since I do not know what chnaged to begin with and so cannot track the problem.

Thanks.

posted date: 2009-04-14 08:03:00


Re: PHP: getting a “use of undefined constant COOKIE_LOGIN” how do I fix this?#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-14 08:03:01


Re: PHP: getting a “use of undefined constant COOKIE_LOGIN” how do I fix this?#3
You need to surround the array key by quotes:if (isset($_COOKIE[(COOKIE_LOGIN(]) && !empty($_COOKIE[(COOKIE_LOGIN(])) setcookie((COOKIE_LOGIN(,$objUserSerialized,time() - 86400 );PHP converts unknown literals to strings and throws a warning. Your php.ini probably had the error reporting level to not display warnings but someone may have updated it or something. In either case, it is bad practice to take advantange of PHP(s behavior in this case.For more information, check out the php documentation:Always use quotes around a string literal array index. For example, $foo[(bar(] is correct, while $foo[bar] is not.This is wrong, but it works. The reason is that this code has an undefined constant (bar) rather than a string ((bar( - notice the quotes). PHP may in future define constants which, unfortunately for such code, have the same name. It works because PHP automatically converts a bare string (an unquoted string which does not correspond to any known symbol) into a string which contains the bare string. For instance, if there is no defined constant named bar, then PHP will substitute in the string (bar( and use that.

posted date: 2009-04-14 08:05:00


Re: PHP: getting a “use of undefined constant COOKIE_LOGIN” how do I fix this?#4
You can(t say $_COOKIE[COOKIE_LOGIN] without error unless COOKIE_LOGIN is an actual constant that you have defined, e.g.:define("COOKIE_LOGIN", 5);Some people have habits where they will write code like:$ary[example] = 5;echo $ary[example];Assuming that "example" (as a string) will be the array key. PHP has in the past excused this behavior, if you disable error reporting. It(s wrong, though. You should be using $_COOKIE["COOKIE_LOGIN"] unless you have explicitly defined COOKIE_LOGIN as a constant.

posted date: 2009-04-14 08:08:00


Re: PHP: getting a “use of undefined constant COOKIE_LOGIN” how do I fix this?#5
See also my attempt at a canonical answer for causes of this error message.

posted date: 2011-11-05 22:50:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.