特定控制器的Codeigniter会话类禁用 [英] Codeigniter Session class disable for particular controller

查看:59
本文介绍了特定控制器的Codeigniter会话类禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在codeigniter中拥有了应用程序,现在我正在通过该应用程序开发android。使用此应用程序作为服务器端并在android中进行客户端控制台。在服务器中,我维护会话。但是在android请求中,我无法维护会话。取而代之的是,我会在登录请求的第一个请求中在服务器中创建GUID,并存储在客户端,然后存储在客户表中,之后,对于每个请求,客户端都会发送GUID进行身份验证。
现在我的问题是每个从android codeigniter获取的请求都使用不同的会话ID创建会话(每个请求都生成新的会话ID)。如何避免创建会话并将其存储到数据库中。(仅用于android请求,但必须存储浏览器请求)

I'm having application in codeigniter already, now i'm developing the android from this application. Using this application as a server side and doing client console in android. In server i'm maintained the session. But in android request i can't maintain the session. Instead of that i'm creating GUID in server at the first request of login request and storing at client side and also storing at customer table, afterwards for each request client will send the GUID for authentication. Now what is my problem is each request getting from android codeigniter create session with different session id(each request generating new session id). How to avoid creating session and storing into database.(Only for android request, but browser request it have to store)

推荐答案

I设法在Codeigniter 3.1.3中扩展CI_Session。
这是我的工作:

I managed to extend CI_Session in Codeigniter 3.1.3. Here is what I did:

创建文件应用程序/库/Session/MY_Session.php

Create a file application/libraries/Session/MY_Session.php

<?php                                                                                                                                                                                           
defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Session extends CI_Session {

    public function __construct(array $params = array())
    {   
        if ( $this->ignore_sessions() )
            return;
        parent::__construct();
    }   

    function ignore_sessions()
    {   
        $uri = str_replace ("//", "/", $_SERVER['REQUEST_URI']);
        if ( strpos($uri, '/ignore_this_controller/') === 0 ) 
            return true;
        return false;
    }   
}  

您可能还希望将会话添加到您的config / autoload.php:

You might also want to add 'session' to your config/autoload.php:

$autoload['libraries'] = array('session',....)

这篇关于特定控制器的Codeigniter会话类禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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