在codeigniter的url中处理问号 [英] Handling question mark in url in codeigniter

查看:304
本文介绍了在codeigniter的url中处理问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个付款方法,成功返回一个url,如mysite / payment / sucess?auth = SDX53641sSDFSDF,但由于我使用codeigniter,url中的问号不适用于我。
我试过路由,但它did not工作。作为最后的手段我创建了一个pre系统钩子并取消设置GET部分从url,我不得不设置

I am using a payment method which on success returns a url like mysite/payment/sucess?auth=SDX53641sSDFSDF, but since i am using codeigniter, question marks in url are not working for me. I tried routing but it didnt work. As a final resort i created a pre system hook and unset the GET part from the url for with i had to set

$config["uri_protocol"] = "REQUEST_URI";

它的工作方式,但我的网站中的所有其他链接没有按预期工作,尝试更改uri_protocol但不能以任何方式使它工作。
所以基本上我的问题是处理我的url中的?auth = SDFSEFSDFXsdf5345sdf部分,每当paypment方法重定向到我的网站上面提到的url,它被重定向到主页,而不是控制器内的功能。
我如何处理这个,我使用codeIgniter 1.7版本,和couldnt找到任何方式。
请建议一些解决方案。

It worked that way but all other links in my site were not working as intended, tried changing the uri_protocol but could not make it work by any means. So basically my problem is handling the ?auth=SDFSEFSDFXsdf5345sdf part in my url, whenever the paypment method redirects to my site with the url mentioned above, it gets redirected to homepage instead of the function inside controller. How can i handle this, i'm using codeIgniter 1.7 version, and couldnt find any way. Please suggest some solution.

推荐答案

我想我会扩展核心URI类, /libraries/MY_URI.php这将扩展CI_URI类,然后复制_fetch_uri_string方法,这里你可以添加你的逻辑如果$ _SERVER ['QUERY_STRING']存在:

I think I would extend the core URI class, by creating new file at application/libraries/MY_URI.php which will extend the CI_URI class, then copy the _fetch_uri_string method and here you can add your logic if the $_SERVER['QUERY_STRING'] is present:


class MY_URI extends CI_URI
{
    function __construct()
    {
        parent::CI_URI();
    }

    //Whatever this method returns the router class is using to map controller and action accordingly.
    function _fetch_uri_string()
    {
        if(isset($_SERVER['QUERY_STRING']) AND !empty($_GET['auth']))
        {
            //Do your logic here, For example you can do something like if you are using REQUEST_URI
            $this->uri_string = 'payment/success/'.$_GET['auth'];
            return;
            //You will set the uri_string to controller/action/param the CI way and process further
        }

        //Here goes the rest of the method that you copied
    }
}

另请注意,您必须对您的网址进行安全检查,否则可以尝试扩展CI_Router类或其他方法(使用少量方法进行少量实验,尽管_set_routing很重要)。这两个类负责拦截的URL并将它们映射到CI中的controller / action / params。

Also please NOTE that you must do security check of your URL and I hope this works for you, otherwise you can try extending the CI_Router class or other methods (experiment little bit with few methods, though the _set_routing is important). These 2 classes are responsible for the intercepted urls and mapping them to controller/action/params in CI.

这篇关于在codeigniter的url中处理问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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