prevent cookie when running script from CLI in codeigniter

本小妞迷上赌 提交于 2019-12-22 17:06:55

问题


Is there a way of preventing session class to set cookie and adding a record in database when calling it from the command line?


回答1:


The simplest way I think would be to extend the Session class like this :

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

class MY_Session extends CI_Session
{
    public function __construct()
    {
        $CI = get_instance();

        if ($CI->input->is_cli_request())
        {
            return;
        }

        parent::__construct();
    }
}

Just place it in the application/libraries folder. And with a controller like this :

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

class Welcome extends CI_Controller
{
    public function no_cli_session()
    {
        $this->load->library('session');
        $this->session->set_userdata('logged', 'yes');
    }
}

When you call the function from your browser the session is set and when you call it from cli it is not.



来源:https://stackoverflow.com/questions/8394225/prevent-cookie-when-running-script-from-cli-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!