PHP custom session save directory_PHP tutorial

WBOY
Release: 2016-07-13 10:24:14
Original
808 people have browsed it

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/');
Copy after login

or:

session_save_path(dirname(__FILE__).'/phpernote/');
Copy after login

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.

Articles you may be interested in

  • php sets the life cycle of session
  • What should I do if PHP reports Fatal error Allowed memory size of... Insufficient memory error Solution
  • How to clear (delete) the files in the specified directory without deleting the directory folder in php
  • php function to calculate the number of days (days) between two dates
  • The difference between php session and cookie
  • phpMyAdmin Cannot start session without errors error solution
  • php gets the timestamp of the start time and end time of the week on the specified date
  • php performance Optimization: Using isset() to determine the string length is faster than strlen()

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/827567.htmlTechArticlephp custom session save directory Today a customer website suddenly reported a bunch of error prompts, the prompt code is as follows: Warning: session_start() [function.session-start]: open(/var/lib/php/s...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template