Home >Backend Development >PHP Tutorial >PHP custom session save directory_PHP tutorial
php custom session save directory
Today a client website suddenly reported a bunch of error prompts, the prompt code is as follows:
Warning: session_start() [function.session-start]: open(/var/lib/php/session/sess_0dj5ol1fp235a0scu79s8c33t1, O_RDWR) failed: Permission denied (13) in /home/wethost/wwwroot/include/seccode. inc.php on line 7
Warning: Unknown: open(/var/lib/php/session/sess_0dj5ol1fp235a0scu79s8c33t1, O_RDWR) failed: Permission denied (13) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0
The above prompt probably means that there is no permission to read the files in the SESSION directory. It must be caused by some modifications made to the virtual host provider's configuration server. In order to avoid trouble, this time we will directly set the session file saving directory in PHP.
Add the following code to the php code, which should be added in front of session_start().
ini_set('session.save_path', dirname(__FILE__).'/phpernote/');
or:
session_save_path(dirname(__FILE__).'/phpernote/');
The above saves the session file generated by the website to the phpernote directory of the current root directory of the website.
Note that not all configuration parameters can be set in scripts. This is related to the scope of the parameters.
The following content refers to the configuration parameter scope description of PHP
PHP_INI_PERDIR: The directive can be modified in the php.ini, httpd.conf or .htaccess file;
PHP_INI_SYSTEM: The directive can be modified in php.ini and httpd.conf;
PHP_INI_USER: Instructions can be modified in user scripts;
PHP_INI_ALL: Instructions can be modified anywhere;
So only parameters in the PHP_INI_USER and PHP_INI_ALL scopes can be set in the script to take effect. The specific scope of parameters can be retrieved on the network.