[英]session error in codeigniter?
when I want to set session data in codeigniter 3 it says error like:当我想在 codeigniter 3 中设置会话数据时,它会显示如下错误:
A PHP Error was encountered
Severity: Warning
Message: mkdir(): Invalid path
Filename: drivers/Session_files_driver.php
Line Number: 117
Backtrace:
File: C:\xampp\htdocs\ci-test\application\controllers\login.php
Line: 7
Function: __construct
File: C:\xampp\htdocs\ci-test\index.php
Line: 292
Function: require_once
Here is the code that where want to set session data.这是要设置会话数据的代码。
$sess_array = array(
'id' => 1,
'username' => 'bikramkc.kc@gmail.com'
);
$this->session->set_userdata($sess_array);
分享一个对我有帮助的解决方案,尝试设置您的配置变量,如:
$config['sess_save_path'] = sys_get_temp_dir();
This error comes when we use directory bases session approach in CodeIgniter.当我们在 CodeIgniter 中使用基于目录的会话方法时会出现此错误。 If we use database based session approach error will go.如果我们使用基于数据库的会话方法错误就会消失。 Use code below -使用下面的代码 -
change your application->config->config.php and set更改您的 application->config->config.php 并设置
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
& Run SQL query & 运行 SQL 查询
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(40) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
PRIMARY KEY (id),
KEY `ci_sessions_timestamp` (`timestamp`)
);
In config.php sess_save_path
should be sys_get_temp_dir();
在 config.php sess_save_path
应该是sys_get_temp_dir();
then it will resolve the error of mkdir(): Invalid path
然后它将解决mkdir(): Invalid path
的错误
The reason you encountered the error is because you didn't have a $config['sess_save_path']
您遇到错误的原因是因为您没有$config['sess_save_path']
Go to you config.php
and set去你config.php
并设置
$config['sess_save_path'] = NULL;
1.Open the config.php on application/config folder 1.打开application/config文件夹下的config.php
2.Browse all the way down to the $config['sess_save_path'] = NULL;
2.一直浏览到$config['sess_save_path'] = NULL;
line.线。
3.Change the NULL
value to BASEPATH.'sessions'
3.将NULL
值改为BASEPATH.'sessions'
It can be due to PHP and codeIgniter version.这可能是由于 PHP 和 codeIgniter 版本。 For me, PHP 7.1.25 and CI 3.0.4 didn't work.对我来说,PHP 7.1.25 和 CI 3.0.4 不起作用。 You can check with session_id().您可以使用 session_id() 进行检查。 Session was refreshed.会话已刷新。 With CI 3.1.2 it works.使用 CI 3.1.2 它可以工作。
在你的 config.php $config['sess_save_path'] = NULL
试试这个
$config['sess_save_path']
in config file.在配置文件中为$config['sess_save_path']
使用绝对路径。If $config['sess_save_path']
is sys_get_temp_dir()
then session data will store in system folder.如果$config['sess_save_path']
是sys_get_temp_dir()
则会话数据将存储在系统文件夹中。
And If you have database table as ci_sessions with below config.php:如果你有数据库表作为 ci_sessions 与下面的 config.php:
$config['sess_driver'] = 'database'; $config['sess_cookie_name'] = 'ci_session';
The data will store in database.数据将存储在数据库中。 In this case you can $config['sess_save_path'] = NULL;
在这种情况下,您可以$config['sess_save_path'] = NULL;
I had a similar case I have a multihost in godaddy and first I corrected the .htacces file我有一个类似的案例,我在 Godaddy 中有一个多主机,首先我更正了 .htacces 文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Then correct the file config.php然后更正文件config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.