Get Querystring in Codeigniter Project

In most of the codeigniter project it is turned off the querystring. And We can easily do anything without enabling the query-string because we can do everything by segment.

Now coming to the point. If you are integrating a payment system in your application and the payment gateway return you like the following method :

 http://www.mydomain.com/checkout/success/payment?ORDER_ID=1234&TIMESTAMP=12345678&PAID=1&METHOD=pay&...bla ... bla

then you should think about enabling the query-string.

But enabling query-string by the config it may turned off the segment. It is a great problem.

So what can we do? There is a good solution for that. Here goes the solution:

 $query_str = $_SERVER['QUERY_STRING'];
 $req_uri = $_SERVER['REQUEST_URI'];
 $org_query = substr($req_uri, strlen($query_str)+1);
 parse_str($org_query, $_GET);
 print_r($_GET);

Now we can get the query string by :

$myOrder = $_GET['</code><code>ORDER_ID</code><code>'];

Isn’t very simple? Happy coding ………….

Advertisements

, , , ,

  1. #1 by Mahmud Ahsan on January 17, 2011 - 1:08 AM

    Cool, but I use below solution for my CI project so I am sharing it with you.

    in controller method:

      parse_str($_SERVER['QUERY_STRING'], $_GET); 
    

    and in config.php the following change

    $config['uri_protocol']	= "PATH_INFO";
    $config['permitted_uri_chars'] = '';
    

    and in .htaccess file

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
    • #2 by Rashedul Islam Sumon on January 17, 2011 - 1:14 AM

      Yeah, Shaon vai it seems ok but you need to change the .htaccess and config but I tried to do it without changing anything 🙂 Anyway like your solution also.

  2. #3 by Silviu on March 7, 2011 - 3:36 PM

    Maybe I’m doing something wrong, but using Mahmud Ahsan solution i had problem with pagination. To solve this issue I had to combine both solutions, and seems to work perfectly 😀

  3. #4 by nerve compression on May 22, 2013 - 5:21 PM

    I’m not that much of a online reader to be honest but your blogs really nice,
    keep it up! I’ll go ahead and bookmark your site to come back in the future. Many thanks

  4. #5 by Jake on May 28, 2013 - 3:02 PM

    Very rapidly this web site will be famous amid all blogging and site-building visitors, due to it’s good articles

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: