Saturday, October 8, 2011

Both sement based and query string(GETmethod) variables in url ofcodeigniter site

By default codeigniter doesn't support query string or get method variables, we can use only segment based url. To enable both segment base and query string (GET method) variables, you need to follow the upcoming steps...

1 ) In yout codeigniter config file change the uri_protocol as specified bellow,


$config['uri_protocol']    = 'AUTO';


$config['uri_protocol']    = 'PATH_INFO';
//  OR

$config['uri_protocol']    = 'ORIG_PATH_INFO';

Some servers does not support 'PATH_INFO' as 'uri_protocol'. Then use 'ORIG_PATH_INFO'.

2 ) In your controller where you want to use query string variable, add the following line in the controller's constructor,


3 ) Now, you are able to use the query string variables in your methods of the controller like given below,


class Search extends CI_Controller{
function __construct(){
function result(){
echo "Search result for Name:".$_GET['name']." and Age:".$_GET['age'];

If your url is,


The above code prints,

Search result for Name:David and Age:22


  1. I notify your post really I am impressed from this post. I was searching for some info to this website , You write very well which is awesome. I enjoyed every bit of your article post. Thanks.
    Awesome Writing. I really enjoyed this post. Thank you so much for sharing.

  2. This comment has been removed by the author.

  3. Good that you posted it here, it helped me a lot. Codeigniter is a good framework but as all the frameworks it’s complicated a bit. It is really hard to master especially if it isn’t only one framework you are working with. This kind of guides and tips you showed us here is helping IT world grow so fast. Reviews on the different services are performing the same task. For example reviews on Master papers could show you things you didn’t know before.