Analysis of session setting method after php disables cookies

黄舟
Release: 2023-03-06 07:42:01
Original
1449 people have browsed it

The example of this article describes the session setting method after PHP disables cookies. Share it with everyone for your reference, the details are as follows:

We all know that there are two ways to pass SESSIONID in the session, based on cookie and based on URL. In order to prevent the client from sending cookies without affecting the customer's login to the website, you can set session.use_trans_sid=1 in php.ini, which means that when the client browser disables cookies, the links on the page will pass the SESSIONID based on the URL. However, many people only set this option and it did not achieve the effect. I also encountered this problem. After some research, I found that there are two more options in the

php.ini file

session.use_cookies=1
session.use_only_cookies=1
Copy after login

Carefully ponder the above English and you will find its meaning

session.use_cookies indicates whether to start a session based on cookies

session.use_only_cookies indicates whether to only open a session based on cookies

So if you want to use the cookie-based method when cookies are turned on in the browser, and use the URL method when cookies are not turned on, make the following settings (the most commonly used method, recommended)

In the php.ini file:

session.use_trans_sid=1
session.use_only_cookies=0
session.use_cookies=1
Copy after login

or in the php program

ini_set("session.use_trans_sid","1″);
ini_set("session.use_only_cookies",0);
ini_set("session.use_cookies",1);
Copy after login

If you use the URL method regardless of whether cookies are turned on in the browser, make the following settings ( This example mainly wants to illustrate the difference between setting session.use_only_cookies and session.use_cookies)
In the php.ini file

session.use_trans_sid=1
session.use_only_cookies=0
session.use_cookies=0
Copy after login

or in the php program

ini_set("session.use_trans_sid","1″);
ini_set("session.use_only_cookies",0);
ini_set("session.use_cookies",0);
Copy after login


Try it yourself and you will understand the difference between session.use_only_cookies and session.use_cookies.

The above is the analysis of the session setting method after PHP disables cookies. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!