[PHP] dialog storage methods

Source: Internet
Author: User
[PHP] explanation of session storage method author: zhanhailiang date: 2013-03-15 first confirm whether the session is automatically enabled or needs to be manually enabled through session_start :; specifies whether the session module automatically starts a session when the request starts. The default value is 0 (not started); Initializesessiononrequeststartup.; php. netses [PHP] session storage method

Author: zhanhailiang date: 2013-03-15

First, check whether the session is automatically enabled or you need to manually enable it through session_start:

; Specifies whether the session module automatically starts a session when the request starts. The default value is 0 (not started); Initialize session on request startup.; http://php.net/session.auto-startsession.auto_start = 0

Client Storage

On the client side, sessions can be stored in cookies or obtained through URL parameters. Server-dependent configuration:

; Specifies whether to use cookies on the client to store Session IDs. The default value is 1 (enabled); Whether to use cookies.; http://php.net/session.use-cookiessession.use_cookies = 1; specifies Whether to use cookies only on the client to store Session IDs .. Enabling this setting can prevent attacks related to passing session IDs through URLs .; This option forces PHP to fetch and use a cookie for storing and maintaining; the session id. we encourage this operation as it's very helpful in combatting; session hijacking when not specifying and managing your own session id. it is; not the end all be all of session hijacking defense, but it's a good start .; http://php.net/session.use-only-cookiessession.use_only_cookies = 1

If you confirm that the session is stored in the cookie, you can configure the configurations of the session stored in the cookie, such as cookie_name, cookie_lifetime, cookie_path, cookie_domain, cookie_secure, cookie_httponly

; Name of the session (used as cookie name).; http://php.net/session.namesession.name = PHPSESSID ; Lifetime in seconds of cookie or, if 0, until browser is restarted.; http://php.net/session.cookie-lifetimesession.cookie_lifetime = 0 ; The path for which the cookie is valid.; http://php.net/session.cookie-pathsession.cookie_path = / ; The domain for which the cookie is valid.; http://php.net/session.cookie-domainsession.cookie_domain = ; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.; http://php.net/session.cookie-httponlysession.cookie_httponly =

Server-side storage

On the server side, you can also store sessions in multiple ways. The default session is stored in the file. session. save_path is the path for creating the storage file.

; Handler used to store/retrieve data.; http://php.net/session.save-handlersession.save_handler = files ; Argument passed to save_handler.  In the case of files, this is the path; where data files are stored. Note: Windows users have to change this; variable in order to use PHP's session functions.;; The path can be defined as:;;     session.save_path = "N;/path";; where N is an integer.  Instead of storing all the session files in; /path, what this will do is use subdirectories N-levels deep, and; store the session data in those directories.  This is useful if you; or your OS have problems with lots of files in one directory, and is; a more efficient layout for servers that handle lots of sessions.;; NOTE 1: PHP will not create this directory structure automatically.;         You can use the script in the ext/session dir for that purpose.; NOTE 2: See the section on garbage collection below if you choose to;         use subdirectories for session storage;; The file storage module creates files using mode 600 by default.; You can change that by using;;     session.save_path = "N;MODE;/path";; where MODE is the octal representation of the mode. Note that this; does not overwrite the process's umask.; http://php.net/session.save-path;session.save_path = "/tmp"

PHP supports the use of session_set_save_handler to implement custom open, close, read, write, destroy and gc processing functions of the session processor. Common session processors include memory allocation (such as mm, you can also use a database for storage.It can be seen that if Session storage and file systems (such as using PostgreSQL Session Save Handler or default file storage files) need to work together, in this case, the custom session processor may lose the session that has not stored data. If the memory type is used for storage allocation, session persistence storage needs to be considered.

Next we will focus on memcache (d ?) Session processor.

The Memcache module provides convenient process-oriented and object-oriented interfaces for memcached. memcached is a resident process cache product generated to reduce the workload of dynamic web applications loading data from databases.
The Memcache module also provides a session processor (memcache ).

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.