如何在 CodeIgniter 中读取 QueryString? [英] How can I read a QueryString in CodeIgniter?
问题描述
我知道之前有人问过它,但我需要它来进行会员跟踪...
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
如何获取该 URL 中列出的参数和 $_GET 参数?
How can I get the params AND the $_GET parameters outlined in that URL?
推荐答案
然而,有时 您需要访问 CodeIgniter 中的 GET 变量.
一个明显的例子是当您使用 API 向您的网站(Paypal 等)发送回发消息时
One glaring example is when you use an API that sends a post-back to your site (Paypal, etc.)
在我看来,最简单的方法是使用您需要的 GET 数据解析服务器变量,因为 $_GET 已被擦除(在我的示例中,REQUEST_URI 具有我的 GET 数据.):
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.
这是一个用法示例.
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屋!