CodeIgniter PHP Framework - Need to get query string

前端 未结 12 1505
挽巷
挽巷 2020-11-27 04:07

I\'m creating an e-commerce site using CodeIgniter.

How should I get the query string?

I am using a Saferpay payment gateway. The gateway response will be li

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 04:37

    You can create a pre_system hook. In the hook class you create, you can grab the desired query params and add them to the $_POST for normal CI processing. I did this for a jQuery Ajax helper.

    For instance:

    (Name this file autocomplete.php or whatever you put as the file name in the hook)

     'Autocomplete',
                    'function' => 'override_get',
                                    'filename' => 'autocomplete.php',
                                    'filepath' => 'hooks',
                                    'params'   => array()
                                    );
    
    *                               
    * 
    */
    
    class Autocomplete {
        function override_get() {
            if (strlen($_SERVER['QUERY_STRING']) > 0) {
                $temp = @array();
                parse_str($_SERVER['QUERY_STRING'], $temp);
                if (array_key_exists('q', $temp) && array_key_exists('limit', $temp) && array_key_exists('timestamp', $temp)) {
                    $_POST['q'] = $temp['q'];
                    $_POST['limit'] = $temp['limit'];
                    $_POST['timestamp'] = $temp['timestamp'];
                    $_SERVER['QUERY_STRING'] = "";
                    $_SERVER['REDIRECT_QUERY_STRING'] = "";
                    $_GET = @array();
                    $url = strpos($_SERVER['REQUEST_URI'], '?');
                    if ($url > -1) {
                        $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $url);
                    }
                }
            }
        }
    }
    
    ?>
    

提交回复
热议问题