Home >Backend Development >PHP Tutorial >The dot (period) in the php cookie is automatically converted to an underscore. The cookie is underlined_PHP Tutorial

The dot (period) in the php cookie is automatically converted to an underscore. The cookie is underlined_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:16:231113browse

There is a problem with the dot (period) in the php cookie being automatically converted to an underscore, and the cookie is underlined

You cannot use dots (periods) in php cookies. In fact, it is not very strict. It should be said that you can use dots in cookie names, but they will be converted. You name a cookie:

$_COOKIE['my.name'] = 1;

Actually you cannot find this value in the cookie via 'my.name', only 'my_name':

echo $_COOKIE[‘my_name’];

php has automatically converted it for you, and the period has been converted to an underscore.

Why does php do this? This is because of $_GET/$_POST/$_SERVER/$_COOKIE. . . The values ​​of these global functions can be directly accessed locally through the register_globals parameter in many previous versions. For example, after turning on register_globals = on, accessing $my_name directly takes the value to 1. If it is $my.name, it does not comply with the PHP variable naming principle. This is not just a problem of periods (.).

Therefore, the naming of $_COOKIE already complies with the PHP naming standard.

Also turning on register_globals is a bad decision because it may overwrite the original value in the script, such as:

// other code
if ($a)
$uc_is_login = true;
// ...

Users only need to send an http request with url?a=1 to be logged in by default. This is a very dangerous practice and should be shut down. In fact, php6 has removed this option.

php cookie usage issues

setcookie("name", "val", expire_time, "/", ".domain.com");
Add a period in front of
.domain.com so that it can be applied to domain.com subdirectory inside.
"/" is the root directory.
This way you can get the saved cookies wherever you go.

php cookie problem, 100 help

Can you use underscores in domain names? My understanding is that you can only use a dash!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/897693.htmlTechArticle There is a problem with the dot (period) in the php cookie being automatically converted to an underscore. The dot (period) cannot be used in the cookie underline php cookie. period), in fact it is not very strict, it should be said that you can use dots...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn