Home > Backend Development > PHP Tutorial > The dot cannot be used in php cookie name, phpcookie usage_PHP tutorial

The dot cannot be used in php cookie name, phpcookie usage_PHP tutorial

WBOY
Release: 2016-07-13 10:16:47
Original
954 people have browsed it

PHP cookie names cannot use dots. phpcookie uses

. This title is not very strict. It should be said that dotted cookie names can be used, but they will be converted. You name one. cookie:

<span>$_COOKIE[‘</span>my.name'] = 1;
Copy after login

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

<span>echo</span> <span>$_COOKIE[‘</span>my_name'];
Copy after login

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:

<span>//</span><span> other code</span>
<span>if</span> (<span>$a</span><span>)
    </span><span>$uc_is_login</span> = <span>true</span><span>;
</span><span>//</span><span> ...</span>
Copy after login

The user only needs 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 cannot save cookies, the value is too small

Cookies will be included when submitting web pages, so cookies generally do not contain large items, otherwise the web page will be very slow.
This is why images and other resources use different domain names from the main website.
The idea above is not the same as session. Session is the unique PHPSESSID (in cookie) corresponding to each user's session.
Give you a picture of the http request.


The dot cannot be used in php cookie name, phpcookie usage_PHP tutorial

Use of cookies in php

date_default_timezone_set("PRC");
setcookie("name","Ronaldiner",time()+3600);
echo "Your name is:". $_COOKIE["name"];
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/896044.htmlTechArticlePHP cookie name cannot use dots. The use of this title by phpcookie is not very strict. It should be said that dots can be used. cookie name, but will be converted, you name a cookie: $_COOKIE[' m...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template