CodeIgniter PHP Framework - Need to get query string

前端 未结 12 1506
挽巷
挽巷 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:34

    // 98% functional
    parse_str($_SERVER['REQUEST_URI'], $_GET);
    

    This in fact is the best way to handle the lack of support for $_GET query strings in CodeIgniter. I actually came up with this one on my own myself, but soon realized the same thing Bretticus did in that you had to slightly modify the way you treated the first variable:

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

    It was only going to be a matter of time before I got to it myself, but using this method is a better one-line solution to everything else out there, including modifying the existing URI library, is isolated to only the controller where it is applicable, and eliminates having to make any changes to the default configuration (config.php)

    $config['uri_protocol'] = "AUTO";
    $config['enable_query_strings'] = FALSE;
    

    With this, you now have the following at your disposal:

    /controller/method?field=value
    /controller/method/?field=value
    

    Verify the results:

    print_r($_GET); // Array ( [field] => value ) 
    

提交回复
热议问题