How to correctly set PHP session control Session_name

Source: Internet
Author: User
Tags php session

Definition: String Session_name ([string $name]) Description:
    1. Configured in PHP.ini as: Session. Name = Phpsessid
    2. When the request begins, the session name is reset and stored to the session. name configuration item.
    3. So if you want to change the php.ini configuration file without changing it, the session_name must be in session_start () or
    4. Session_register() before setting session_name.
Code Demo:
    • [Start session first, then set Session_name]
  1. <?php
  2. /**
  3. * In- Depth understanding of PHP session control
  4. * User:gutops
  5. */
  6. Start a new session
  7. Session_Start ();
  8. Set session_name
  9. Session_name (' phpsessid_new ');
  10. echo session_name (); // output is phpsessid_new
  so sesssion_name not changed, view browser  Cookies name for phpsessid (php.ini in the default settings of the Span class= "Hljs-selector-tag" >session.name)         
    • [Set Session_name again to start session (correct modification mode)]
  1. <?php
  2. /**
  3. * In- Depth understanding of PHP session control
  4. * User:gutops
  5. */
  6. Session_name (' phpsessid_new ');
  7. Session_Start ();
  8. echo session_name (); // output is phpsessid_new
查看浏览器cookies,可以看到name变为PHPSESSID_NEW

How PHP session control is set correctly 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.