在codeigniter中从CLI运行脚本时阻止cookie [英] prevent cookie when running script from CLI in codeigniter

查看:205
本文介绍了在codeigniter中从CLI运行脚本时阻止cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以防止会话类在从命令行调用时设置cookie并在数据库中添加记录?

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

推荐答案

我认为扩展Session类的最简单的方法是这样:

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

当您从浏览器调用函数时设置,当你从cli调用它不是。

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

这篇关于在codeigniter中从CLI运行脚本时阻止cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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