php how to start Session session

Session of different settings and Cookie, you must first start, you must call session_start () function in PHP, so that PHP core program and Session variables related to the built environment pre-loaded into memory. Marble platform accuracy class

 

Use session_start () function to start the session, the form of the following syntax:

1

session_start(void);   // 创建  Session,开始一个会话,进行 Session 初始化

session_start () This function has no parameters and return values ​​are TURE. This function has two major roles, rituals begin a conversation, but returns a session that already exists.

When you first visit the site, session_start () function will create a unique Session ID, and automatically save the Session ID to the client via HTTP Cookie response header. At the same time, create a page with this Session ID named file on the server side, to hold the user's session information. When a user with access to the site again, automatically saves the client the Cookie Session ID to take over the HTTP request header, then the session_start () function will not go to assign a new Session ID, and It is the server's hard disk to find this session ID and session file of the same name, before reading out the saved user session for this information, the application in the current script, to track the user's purpose. So during the session, with a user when any page, all using the same Session ID on the access server.

Note: In general, session_start () function call at the beginning of the page position, then the session variables are registered in the data $ _SESSION.

Note: If you use the Cookie-Based Session, before using this function is turned Session, the content can not have any output. Because when Cookie the Session really turned on, calling session_start () function generates a unique a Session ID, you need to save the Cookie client computer, so use session_start () before the function browser can not have any output, even spaces and blank line does not work, or an error output string produced.

If you do not want to use in every script session_start () function to open the Session, which can then php.ini settings session.auto_start = 1, every time you do not need to call session_start () function before using the Session. But this option is enabled hungry oil some restrictions, it is not put objects into the Session because the class definition must be loaded before starting the Session. It is generally not recommended to open session.auto_start Session.

Guess you like

Origin www.cnblogs.com/furuihua/p/12197981.html