Home  >  Article  >  Backend Development  >  php framework - Some php blog frameworks add a static random character to each cookie name. Why is this?

php framework - Some php blog frameworks add a static random character to each cookie name. Why is this?

WBOY
WBOYOriginal
2016-08-18 09:15:591037browse

For example, these cookie names:
5xHK8D3fgc_user_info
5xHK8D3fgc_comment_author
5xHK8D3fgc_comment_email

Why do you do this?

Reply content:

For example, these cookie names:
5xHK8D3fgc_user_info
5xHK8D3fgc_comment_author
5xHK8D3fgc_comment_email

Why do you do this?

Imagine a scene like this:

You bought a virtual host VPS, and then deployed a set of blogging programs. Suddenly your girlfriend told you that she also wanted one, so you deployed a set.
However, you only have one domain name, and you are smart and thought of using a subdomain name to distinguish it, OK! So you quickly fulfilled this need.

But you find that after logging in with your girlfriend, the login status under your own domain name is actually lost, and you feel something is wrong
So, after checking over and over again, you finally found "when accessing under your own blog" under the http packet capture tool , what was actually passed was the cookie information from my girlfriend.” The cookies they use have the same name, but cookie.domain is still .xxx.com

In fact, this is the role of the cookie prefix, and it is also the reason why many backgrounds need to set cookie.domain. A random prefix can prevent this from happening.

This is actually called cookie prefix, and the cookie prefix can be customized.

In fact, the previous PHPers had many bad habits, so the questioner does not need to think too much.

I don’t quite understand cookies
Tell me about the prefix of session
On the same server, if you run multiple websites and the session directories are the same
For example, if you define login is_login = true in a web project
Another web is not logged in But it is also possible to obtain the login
But if you use the prefix
web1_is_login
will not affect web2_is_login

Cookie prefix, just like database table prefix.

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