php codeigniter 中的会话错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31042456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:12:41  来源:igfitidea点击:

session error in codeigniter?

phpcodeignitersession

提问by bikram kc

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' => '[email protected]'
       );
$this->session->set_userdata($sess_array);

回答by Wellyngton

Sharing a solution that helped me, try set your config variable like:

分享一个对我有帮助的解决方案,尝试设置您的配置变量,如:

$config['sess_save_path'] = sys_get_temp_dir();

回答by Md. Khairul Hasan

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`)
);

回答by Md Rashadul Islam

In config.php sess_save_pathshould be sys_get_temp_dir();then it will resolve the error of mkdir(): Invalid path

在 config.phpsess_save_path应该是sys_get_temp_dir();然后它会解决的错误mkdir(): Invalid path

回答by Saty

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.phpand set

去找你config.php并设置

$config['sess_save_path'] = NULL;

回答by ben

It can be due to PHP and codeIgniter version. For me, PHP 7.1.25 and CI 3.0.4 didn't work. You can check with session_id(). Session was refreshed. With CI 3.1.2 it works.

这可能是由于 PHP 和 codeIgniter 版本造成的。对我来说,PHP 7.1.25 和 CI 3.0.4 不起作用。您可以使用 session_id() 进行检查。会话已刷新。使用 CI 3.1.2 它可以工作。

回答by Ambal Mani

Try this in your config.php $config['sess_save_path'] = NULL

在你的 config.php 中试试这个 $config['sess_save_path'] = NULL

回答by Engr Syed Rowshan Ali

  1. Use absolute path for $config['sess_save_path']in config file.
  2. Point it to your writable temporary directory.
  3. Make sure the directory is under the directory allowed in apache or nginx config.
  1. $config['sess_save_path']在配置文件中使用绝对路径。
  2. 将其指向您的可写临时目录。
  3. 确保该目录位于 apache 或 nginx 配置中允许的目录下。

回答by Md Rashadul Islam

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';

$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;

回答by Faisal

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;line.

2.一直浏览到该$config['sess_save_path'] = NULL;行。

3.Change the NULLvalue to BASEPATH.'sessions'

3.将NULL值更改为BASEPATH.'sessions'

回答by Jaimito Ojalonzo

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?/ [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/ [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/ [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;