如何读取CodeIgniter中的QueryString? [英] How can I read a QueryString in CodeIgniter?

查看:242
本文介绍了如何读取CodeIgniter中的QueryString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道它之前已被问过,但我需要它进行联属网络跟踪...



http://www.mysite.com/controller/method/params?affiliate=123&sub_id=456 p>

如何获取该网址中列出的params和$ _GET参数?

解决方案

但是,有时候需要访问在CodeIgniter中的GET变量



一个明显的例子是,当您使用发送回您的网站(Paypal等) p>

在我看来,最简单的方法是使用您需要的GET数据解析服务器变量,因为$ _GET已被擦除(在我的示例中,REQUEST_URI有我的GET数据。 ):

  parse_str(substr(strrchr($ _ SERVER ['REQUEST_URI'],?),1),$ _GET ); 

这样就可以在不需要全局更改框架设置的情况下,



这是一个使用示例。

  
function postback(){
parse_str(substr(strrchr($ _ SERVER ['REQUEST_URI'],?),1),$ _GET);
$ receipt = $ this-> input-> xss_clean($ _ GET ['receipt']);
}
}


I know it's been asked before, but I need it for affiliate tracking...

http://www.mysite.com/controller/method/params?affiliate=123&sub_id=456

How can I get the params AND the $_GET parameters outlined in that URL?

解决方案

And yet, sometimes you need access to GET variables in CodeIgniter.

One glaring example is when you use an API that sends a post-back to your site (Paypal, etc.)

The easiest way, in my opinion, is to parse a server variable with the GET data you need since $_GET has been wiped (in my example, REQUEST_URI has my GET data.):

parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);

This allows the functionality exactly where you need it without requiring a global change to framework settings.

Here is a usage example.

class Pgate extends Controller {
   function postback() {
      parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);
      $receipt = $this->input->xss_clean($_GET['receipt']);
   }
}

这篇关于如何读取CodeIgniter中的QueryString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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