php cookie midpoint (period) automatically changed to underscore problem

  • 2021-07-22 09:19:37
  • OfStack

php cookie can't use the dot (period), which is actually not very strict. It should be said that the dot cookie name can be used, but it will be converted. You name 1 cookie:

$_ COOKIE ['my. name'] = 1;

You can't actually find this value in cookie through 'my. name', only 'my_name':

echo $_COOKIE ['my_name'];

php has automatically converted for you, and the period has changed to underline.

Why is php doing this? This is because $_ GET/$ _ POST/$ _ SERVER/$ _ COOKIE. . . In many previous versions, the values of these global functions can be accessed directly locally through the register_globals parameter. For example, after register_globals = on is turned on, the value of $my_name is accessed directly to 1. If it is $my. name, it does not conform to the php variable naming principle, which is not only a question of period (.).

Therefore, the naming of $_ COOKIE already conforms to the php naming standard.

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

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

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


Related articles: