如何在Codeigniter中记录每个GET和POST数据? [英] How to log every GET And POST data in Codeigniter?

查看:40
本文介绍了如何在Codeigniter中记录每个GET和POST数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台服务器,许多IOS和Android客户端在该服务器上发送HTTP请求,并根据该请求向他们发送一些响应.

I have a Server on which many IOS and Android Client send HTTP request, and based on that request i send them some response back.

现在,我要将所有传入请求存储在我的日志中,以便对调试有所帮助.我也想存储服务器发回的响应.

Now I want to store all the incoming request in my logs so it can be helpful for debugging. Also i want to store what my server sent back in response.

我在服务器上收到的请求:

$data = $this->license_m->array_from_get(array('request','device_id','product','software_version','platform_os','platform_model','platform'));

响应服务器回馈

 $response = array(
                     'response_code' =>200 ,
                         'request'=> $this->input->get('request'),
                     'device_id'=> $this->input->get('device_id'),
                     'allowed_hours'=> $remaining_hours,
                     'product'=>'mlc',
                     'url'=>NULL
                 );

                return $this->output
                ->set_content_type('Content-Type: application/json')
                ->set_output(json_encode($response));

现在,我想将所有这些数据记录到我的codeigniter的日志中.该怎么做?

Now i want to log all this data into logs of my codeigniter. How to do that?

我尝试过这个:

log_message('debug',print_r($data,TRUE));

但这会保存请求数组或响应数组,而不是全部保存

but this saves either request array or the response array not both of them

我的许可证类别:

<?php

/**
*
*/
class License extends Admin_Controller
{

 public function __construct()
 {
     parent::__construct();

     $this->load->model('license_m');
 }

 public function index($id = NULl)
 {

     $req = $this->input->get('request');



     if($req =="trial")
     {
        $request = array(
         'request' => $this->input->get('request'),
         'device_id' => $this->input->get('device_id'),
         'launch_date'=> $this->input->get('launch_date'),
         'allowed_hours'=>$this->input->get('trial_usage'),

         'product'=>$this->input->get('product'),
         'software_version'=> $this->input->get('software_version'),
         'platform_os'=> $this->input->get('platform_os'),
         'platform'=> $this->input->get('platform'),
         'platform_model'=> $this->input->get('platform_model')
             );



        /* checking if device id exists */
          $data = $this->license_m->array_from_get(array('request','device_id','product','software_version','platform_os','platform_model','platform'));

  $this->db->where('device_id',$data['device_id']);
  $this->db->where('request','activation');

  $query = $this->db->get('activation');


 $response = array(
                             'response_code' =>200 ,
                             'device_id'=> $this->input->get('device_id'),
                             'expiry_date'=> '20201231-235959',
                             'product'=>'mlc',
                             'url'=>NULL ,
                             'request'=> $this->input->get('request')


                             );


                             return $this->output
                             ->set_content_type('Content-Type: application/json')
                             ->set_output(json_encode($response));

推荐答案

您可以覆盖CI_Output

You could override the CI_Output

class MY_Output extends CI_Output {
    public function _display($output = '') {
        log_message('debug', '[Request: '.@json_encode(get_instance()->get_post(null)).'][Response: '.@json_encode($output).']');

        return parent::_display($output);
    }
}

这篇关于如何在Codeigniter中记录每个GET和POST数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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