How to correctly set PHP session control Session_name

Source: Internet
Author: User
Tags php session

PHP session control how to set the Session_name definition correctly: String session_name ([string $name]) Description:
在php.ini中配置为:session.name = PHPSESSID在请求开始的时候,会话名称会被重置并存储到session.name配置项。所以要想在不改变php.ini配置文件的情况下,更改session_name 必须要在 session_start()或session_register()之前设置session_name。
Code Demo:
    • [Start session first, then set Session_name]

      <?php/*** 深入理解PHP会话控制* User: gutops*///启动新会话session_start();//设置session_namesession_name(‘PHPSESSID_NEW‘);echo session_name();    //输出为PHPSESSID_NEW

      This sesssion_name does not change, check the browser cookie name is PHPSESSID (the default setting in PHP.ini session.name)

    • [Set Session_name again to start session (correct modification mode)]
<?php/** * 深入理解PHP会话控制 * User: gutops */session_name(‘PHPSESSID_NEW‘);session_start();echo session_name();    //输出为PHPSESSID_NEW
查看浏览器cookies,可以看到name变为PHPSESSID_NEW

How to correctly set PHP session control Session_name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.