Can you assign the value of a constant as the name of a cookie in PHP?

0

For example:

<?php
define('COOKIEOUT', 'MyCookie');

setcookie(COOKIEOUT, 'test', time() + (86400* 7), '/', 'domain.com', true, true);

I tried but what I get is an undefined index error on the line where the cookie is set.

The idea of doing this would be to have a PHP configuration file and using include get configurations.

In this case it would be if you wanted to change the name of the cookie, to do it simply in the PHP file to include, so it would affect all the cookies in which the name obtained from the constant is defined.

SOLVED:

replace

setcookie(COOKIEOUT, 'test', time() + (86400* 7), '/', 'domain.com', true, true);

for

setcookie(COOKIEOUT, test, time() + (86400 * 7), '/'); // 86400 = 1 day

the subject of the include I do not usually use it until the tests go well, that is, the constants to be exported are in the same file, once it works I export them to a different file and perform the respective include / require.

    
asked by eZe 22.06.2018 в 06:49
source

0 answers