There are many php.ini file configuration in the Chinese language, but for PHP beginners in the PHP run environment to build configuration is still easy to confused, today, a different angle to share how to php.ini configuration, in order to achieve the effect of solving the actual problem, the beginning of PHP tutorial the method details how to configure the session via PHP.ini to implement the basic session application.
We know that in the use of PHP shopping cart, user login and other interactive website development, session is a good solution, if using XAMPP,appserv and other PHP installation package, in general, PHP Session setup system will be configured if you manually configure the PHP runtime environment, we need to use PHP.ini to configure the session, the following details how to perform session configuration.
PHP Operating Environment Description
I am using dedeampz,php version 5.2.4, if you are manually installing the PHP runtime environment, you need to rename php.ini-dist or php.ini-recommended to php.ini and copy it to the Windows directory.
Session configuration instructions in php.ini
Here are the necessary configuration steps to get the session running
Manually configure the PHP runtime environment, the most easily forgotten is the server side session file storage directory configuration work, open the php.ini file, search session, find Session.save_path, the default value is/tmp, On behalf of the session file saved in the C:/tmp directory, the default TMP directory is not created, you can create a TMP directory under the C drive, or create a different directory, such as LEAPSOULCN, and then modify the value of Session.save_path, and remove;
Session.save_path = '/LEAPSOULCN ';
Precautions:
1, generally in order to ensure the security of the server, the Session.save_path value is best set to the external network can not access the directory, in addition, if you are in the Linux server session configuration, please be sure to configure this directory as read and write permissions, Otherwise, an error will be taken when performing the session operation.
2, in the use of session variables, in order to ensure the security of the server, it is best to set register_globals to off, to ensure that the global variables are not confused, in the use of Session_register () register the session variable, you can through the system global variables $_session to access, such as you register the LEAPSOULCN variable, you can access this variable by $_session[' LEAPSOULCN '].
Session.save_path Configuring additional notes to be translated from the php.ini configuration file
You can use "N; [MODE;] /path "This mode defines the path, and N is an integer that represents a subdirectory with n-level depth, instead of saving all the data files in one directory.
[MODE;] Optionally, you must use the 8 binary number, which is the default of 600 (=384), which represents the maximum number of session files saved per directory. [MODE;] Does not overwrite the umask of the process. PHP does not automatically create these folder structures. Can be created using the mod_files.sh script under the Ext/session directory. If the folder can be accessed by insecure users (such as the default "/tmp"), a security breach will be created. Automatic garbage collection will expire when n>0, see the section on garbage collection below.
If you have multiple virtual hosts on your server, it is recommended that you set up separate directories for each of the different virtual hosts.
At this point the most basic session configuration is complete, you just save php.ini, and restart Apache, you can use the session function.
Additional session configuration Instructions
Session.save_handler = "Files"
By default, the session data is accessed by file, if you want to use a custom processor to access session data, such as a database, with "user".
Session.use_cookies = 1
Whether to use cookies to save session SessionID on the client, by default, by using cookies
session.use_only_cookies = 0
Whether to use cookies to save the session SessionID on the client, this option allows the administrator to prevent the user from passing the ID via the URL, which defaults to 0, and if disabled, the client will not work if the cookie is disabled.
Session.name = "Phpsessid"
Session ID name to use as cookie name
Session.auto_start = 0
Whether to start the session automatically, the default does not start, we know that when using the session function, we basically in each PHP script head will be through the session_start () function to start the session, if you start this option, The session is automatically started on each script header and does not require each script header to start the session with the Session_Start () function, it is recommended to turn off this option, using the default value.
Session.cookie_lifetime = 0
The lifetime of the cookie passed SessionID (in seconds), 0 means only valid during browser opening.
session.gc_probability = 1
Session.gc_divisor = 100
Defines the probability of starting a garbage collection program each time the session is initialized. The formula is as follows: Session.gc_probability/session.gc_divisor, such as 1/100, indicates that there is a 1% probability of starting the garbage collection program, the more frequent the session page, the smaller the probability. The recommended value is 1/1000~5000.
Session.gc_maxlifetime = 1440
Set the saved session file lifetime, more than this parameter sets the number of seconds, the saved data will be treated as ' junk ' and cleaned by the garbage collector. The judging criteria is the last time the data was accessed (for the FAT file system is the last time to refresh the data). If multiple scripts share the same Session.save_path directory but differ session.gc_maxlifetime, the minimum value in all session.gc_maxlifetime directives will prevail.
If you set the Session.save_path option to use subdirectories to store session data files, the garbage collector does not start automatically, and you must use your own shell scripts, cron entries, or other methods to perform garbage collection.
For example, set the Session.gc_maxlifetime=1440″ (24 minutes):
Cd/path/to/sessions; Find-cmin +24 | Xargs RM
The above is a description of some of the commonly used session configuration options, and more session configuration options indicate that you can refer to the instructions in the php.ini file.
So far In the php.ini configuration file to configure the session of the PHP tutorial is complete, through the above steps of practice and learning, the basic session function can be used, as for the session performance and other aspects of the server environment and needs to be fine-tuned, this has to experience.
Reprint address: Click on me.
"Reprint" PHP. INI Configuration: Session Configuration Detailed Instructions tutorial