PHP中设置Session选项的方法及参数详解

需积分: 0 0 下载量 22 浏览量 更新于2024-01-23 收藏 1.86MB DOCX 举报
Day 21 Notes 1: Session_set_cookie_params() is used to set a PHP configuration option. It is recommended to use this method. The parameters for this function include the expiration time, the valid path, the valid domain, whether to only transmit over a secure connection, and whether to use the HTTPONLY flag. In terms of syntax, there are some issues with SESSION. It supports multiple data types. The byte unit is used to measure storage space, where 1 byte is equal to 8 bits. The minimum storage unit is a bit. Bandwidth is measured in bits, for example, 10Mbit. It is important to note that for object-type data, when storing an object in a session, you need to retrieve the corresponding object class using Unserialize(). Why? Because the data stored in the session is serialized. To use sessions in PHP, you need to enable it first. It is recommended not to automatically start sessions. Opening the session multiple times will result in ignoring the subsequent openings, but it will trigger a notice-level error. To solve this issue, you can add "@" to suppress the error when opening the session. Session attributes have default values. The session expires when the browser is closed by default. The valid path is set as "/," which means it is valid for the entire website. The valid domain is set as the current domain by default. The options for whether to only transmit over a secure connection and whether to use the HTTPONLY flag are both set as non-default. The source of session attributes is stored in the COOKIE. Overall, Session_set_cookie_params() is a useful function for setting PHP configuration options related to sessions. It is important to be aware of the syntax and to properly manage the opening and closing of sessions to avoid errors. The session attributes also play a crucial role in determining the behavior and security of the session.
2022-08-08 上传