PHPSession configuration (php. ini) Description Tutorial. In PHP, we can directly set the Session configuration in php. ini. below I will introduce you to some reference instructions for specific session configuration in php. ini. Php. session configuration in ini indicates that the Session configuration in PHP can be directly configured in php. set in ini. next I will introduce you to php. reference for configuring session in ini.
Session configuration in php. ini
The following describes the necessary configuration steps for session running.
When you manually configure the PHP runtime environment, the easiest thing to forget is the storage directory configuration of the session file on the server side. open php. ini file, search for the Session, and find the session. save_path. the default value is/tmp, which indicates that the session file is saved in the c:/tmp Directory. by default, the tmp directory is not created. you can create the tmp directory under disk c, or create another directory, such as leapsoulcn, and then modify the session. and remove the value of save_path; that is
Session. save_path = '/leapsoulcn ';
Note:
1. generally, to ensure server security, session. it is best to set the save_path value to a directory that cannot be accessed from the internet. if you configure the session on a linux server, you must configure the directory as a read/write permission, otherwise, an error is reported during the session operation.
2. when using the session variable, it is best to set register_globals to off to ensure that the global variables are not obfuscated. when using session_register () to register the session variable, you can access this variable through the system global variable $ _ SESSION. for example, if you have registered the leapsoulcn variable, you can access this variable through $ _ SESSION ['leapsoulcn. PHP environment variables $ _ SERVER and system constants
Session. save_path other configuration instructions, translated from the php. ini configuration file
You can use the "N; [MODE;]/path" MODE to define the path. N is an integer, indicating that the depth of N layers is used, instead of saving all data files in a directory.
[MODE;] (optional) it must use an octal number. the default value is 600 (= 384), indicating the maximum number of session files saved in each directory. [MODE;] the umask of the process is not rewritten. Php does not automatically create these folder structures. You can use the mod_files.sh script in the ext/session directory to create a file. If the folder can be accessed by insecure users (such as the default "/tmp"), a security vulnerability will occur. Automatic garbage collection fails when N> 0. for details, refer to the following section about garbage collection.
If your server has multiple virtual hosts, we recommend that you set different directories for each virtual host.
Now the most basic session configuration is complete. you only need to save php. ini and restart apache to use the session function.
Other session configurations
Session. save_handler = "files"
By default, session data is accessed as files. if you want to use a custom processor to access session data, such as databases, you can use "user ".
Session. use_cookies = 1
Whether to use cookies to save session sessionid on the client. by default, cookies are used.
Session. use_only_cookies = 0
Whether to use the cookie to save the session sessionid on the client. This option allows the administrator to disable the user from passing the id through the URL. the default value is 0. if the cookie is disabled, if the client disables cookies, the session will not work.
Session. name = "PHPSESSID"
Session identifier used as cookie name
Session. auto_start = 0
Whether to automatically start the session. it is not started by default. we know that when using the session function, we basically start the session in each php script header through the session_start () function, if you enable this option, the session will be automatically started in each script header. you do not need to start the session using the session_start () function in each script header. we recommend that you disable this option by default.
Session. cookie_lifetime = 0
The Cookie validity period (in seconds) for which sessionid is passed. 0 indicates that the Cookie is valid only when the browser opens.
Session. gc_probability = 1
Session. gc_pisor = 100
Defines the probability of starting the garbage collection program each time a session is initialized. The calculation formula is as follows: session. gc_probability/session. gc_pisor. for example, 1/100 indicates that a 1% probability starts the garbage collection program. The more frequently session pages are accessed, the smaller the probability is. Recommended value: 1/1000 ~ 5000.
Session. gc_maxlife time = 1440
Set the lifetime of the session file to be saved. after this parameter is set to a few seconds, the stored data will be treated as 'spam 'and cleared by the garbage collection program. The criterion is the last time the data is accessed (for the FAT file system, the last time the data is refreshed ). If multiple scripts share the same session. save_path directory but the session. gc_maxlifetime is different, the minimum value in all session. gc_maxlifetime commands prevails.
If you are in session. the save_path option sets sub-directories to store session data files. the garbage collection program will not start automatically. you must use your own shell script, cron item, or other methods to perform garbage collection.
For example, set "session. gc_maxlifetime = 1440" (24 minutes ):
Cd/path/to/sessions; find-cmin + 24 | xargs rm
The preceding section describes common session configuration options. For more information about session configuration options, see the description in the php. ini file.
So far, in php. the PHP Tutorial on session configuration in the ini configuration file is complete. through the above steps and practices, the basic session functions can be used, the session performance and other aspects need to be fine-tuned according to the server environment and requirements.
Appendix 1
[Session]
Session. save_handler = files; control method for saving/retrieving data
Session. save_path = C: wintemp; parameters passed to the controller when save_handler is set to a file,
; This is the path where the data file will be saved.
Session. use_cookies = 1; whether to use cookies
Session. name = PHPSESSID
The name of the session used in the cookie.
Session. auto_start = 0; initialize the session when the request starts.
Session. cookie_lifetime = 0; the time when the cookie is saved in seconds,
; Or 0 until the browser is restarted
Session. cookie_path =/; valid cookie path
Session. cookie_domain =; valid domain of the cookie
Session. serialize_handler = php; controller used to connect data
Php is the standard controller of PHP.
Session. gc_probability = 1; percentage of 'garbage collection (fragment) 'processes
; The possibility of starting each session initialization.
Session. gc_maxlifetime = 1440; after the number of seconds, the stored data will be treated
; 'Garbage 'and cleared by the gc process.
Session. referer_check =; check the HTTP reference to invalidate the ids contained in the URL.
Session. entropy_length = 0; the number of bytes read from the file
Session. entropy_file =; specify the session id created here
; Session. entropy_length = 16
; Session. entropy_file =/dev/urandom
Session. cache_limiter = nocache; set to {nocache, private, public} to determine the HTTP
; Cache problems
Session. cache_expire = 180; Document expired after n minutes
Session. use_trans_sid = 1; use the transitional sid support.
; -- Enable-trans-sid
Url_rewriter.tags = "a = href,
You can directly set the reset Session configuration in php. ini. below I will introduce some reference instructions for configuring the session in php. ini. Session configuration instructions in php. ini...