重定向后Codeigniter 3.1.3 flash_data丢失 [英] Codeigniter 3.1.3 flash_data lost after redirect

查看:63
本文介绍了重定向后Codeigniter 3.1.3 flash_data丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑此控制器方法

public function authenticate_session($user, $access_token) {
    $this->output->enable_profiler(TRUE);

    $user = $this->user_model->find_users(array("email" => $user, "access_token" => $access_token), "email, last_activity, access_token");

    if ($user) {
        $this->load->library('session');

        $this->session->set_flashdata('post_data', $this->input->post(NULL));

        redirect("v1/transactions_controller/pay");
    } else {
        redirect("v1/sessions/unauthenticated");
    }
}

交易控制器中的付款方式

And the pay method in the transactions controller

public function pay() {
        $this->output->enable_profiler(TRUE);

        $this->load->library('session');

        var_dump($this->session->flashdata());
}

var_dump($ this-> session-> flashdata()); 给我 array(0){}

我检查了所有我知道的地方,每个人似乎都说会话库中的flash_data对我而言是最佳选择.用户通过身份验证后,我需要将这些POST参数从初始请求传递到事务控制器.如果我删除重定向并简单地执行 var_dump($ this-> session-> flashdata()); ,我就会看到期望的结果(来自上一个请求的POST数据),但之后不会传递重定向.

I've checked everywhere I know to and everyone seems to be saying that flash_data in the session library is the best option for me. I need to pass those POST parameters from the initial request on to the transactions controller once the user has been authenticated. If I remove the redirect and simply do var_dump($this->session->flashdata()); I see what I expect (POST data from the previous request), but it's not passing after the redirect.

使用 redirect("v1/transactions_controller/pay",刷新"); 似乎并没有进入新的控制器,而是在身份验证控制器方法上进行了刷新,但是我确实可以看到我的flashdata.难道我做错了什么?应该为我的服务器配置某种方式以使其正常工作吗?我已经将session_start()添加到我的index.php中,但是它引发了一个错误,因为它已经在会话库中,这由需要它的两个控制器加载.

Using redirect("v1/transactions_controller/pay", "refresh"); doesn't seem to actually go to the new controller and instead refreshes in place on the authentication controller method, but I do get to see my flashdata. Am I doing something wrong? Should my server be configured a certain way for this to work properly? I've added session_start() to my index.php, but it threw an error because it's already in the session library, which is loaded by both controllers that need it.

我的会话和cookie变量在config.php中

My session and cookie variables in config.php

$config['cookie_prefix']    = '';
$config['cookie_domain']    = 'localhost';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

推荐答案

您需要为会话创建路径

https://www.codeigniter.com/user_guide/libraries/sessions.html#session-preferences

更改

$config['sess_save_path'] = NULL;

对于以下内容,并确保设置权限0700

To something like below and Make sure you set permission 0700

$config['sess_save_path'] = APPPATH . 'cache/sessions/';

Codeigniter路径函数定义

EXT:PHP文件扩展名

EXT: The PHP file extension

FCPATH:前端控制器的路径(此文件)(CI的根目录)

FCPATH: Path to the front controller (this file) (root of CI)

SELF:此文件的名称(index.php)

SELF: The name of THIS file (index.php)

BASEPATH:系统文件夹的路径

BASEPATH: Path to the system folder

APPPATH:应用程序"文件夹的路径

APPPATH: The path to the "application" folder

还保留Flash数据

$this->session->keep_flashdata('item');
$this->session->keep_flashdata(array('item1', 'item2', 'item3'));

和codeigniter会话tempdata

And codeigniter session tempdata

https://www.codeigniter.com/user_guide/libraries/sessions.html#tempdata

$config['cookie_domain'] = '.localhost';

这篇关于重定向后Codeigniter 3.1.3 flash_data丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆