Welcome Guest, Not a member yet? Register   Sign In
Using codeigniter in QUERY_STRING mode with php fast CGI
#1
Rainbow 

Hello,

I need to use codeigniter in QUERY_STRING mod ($config['uri_protocol'] = 'QUERY_STRING') because of my hosting.
Indeed, my hosting use php fastcgi mod.

So, on my config file I have this :

PHP Code:
$config['uri_protocol'] = 'QUERY_STRING';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE

In my htaccess I have this :

Code:
RewriteRule ^(.*)$ index.php?/$1 [L]

My rules and my website work fine but, I need also to use some query string in my urls.
Because of using this rule :

Code:
RewriteRule ^(.*)$ index.php?/$1 [L]

When I have a page url like this : test.html?data=dog

$_GET is empty... I can't access to $_GET['data']

Do you have any solution for me ?


Thank you.
Reply
#2

why is this set to false? $config['enable_query_strings'] = FALSE;
Reply
#3

(03-20-2015, 12:56 AM)Avenirer Wrote: why is this set to false? $config['enable_query_strings'] = FALSE;

I'ts change nothing if I set to TRUE Sad
Reply
#4

And I set to TRUE, If i do

PHP Code:
<?php redirect('admin/'); ?>

It's not working because codeigniter go to this url http://site.com?admin/ instead of http://site.com/admin/
Reply
#5

@Peter: For security reasons the $_GET items are sanitized, stored and then $_GET is emptied.
If you want to fetch a GET item, use the $this->input->get('data') method.

@Avenirer: enable_query_strings is always set to false from the default Installation.
The name maybe suggests that you can't use urls like test.html?data=dog. But this setting has nothing to do with that.
If you set this setting to true, you choose NOT to use segment based urls like example.com/controller/function but query string based urls example.com/index.php?c=controller&m=function.
Reply
#6

(This post was last modified: 03-20-2015, 08:30 AM by peter.)

The $this->input->get('data') change nothing, is still empty.

I use this controler :

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Site extends CI_Controller {

    public function 
test() {

        echo 
'<pre>';
        
print_r($_GET);
        echo 
'</pre>';

        echo 
$this->input->get('data');
    }




This config :

PHP Code:
$config['uri_protocol'] = 'QUERY_STRING';
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE

And this htaccess :

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

My website is on php fastcgi hosting.

$_GET[] and $this->input->get('data') are still empty when I am trying this url : http://site.com/site/test?data=mydata

Thank you.
Reply
#7

ok, a print_r() of $_GET will give you an empty array because CI stores the data from $_GET elsewhere and empties $_GET as explained.

But you should be able to fetch de GET items using $this-input->get('var name');

I tested this just now with this simple function:
Code:
   function getitnow() {

       echo $this->input->get('data');

   }

and when using the url

Code:
mydomain.com/test/getitnow?data=hello%20world

CI echoed 'Hello world' as a result
Reply
#8

(03-20-2015, 09:29 AM)RogerMore Wrote: ok, a print_r() of $_GET will give you an empty array because CI stores the data from $_GET elsewhere and empties $_GET as explained.

But you should be able to fetch de GET items using $this-input->get('var name');

I tested this just now with this simple function:

Code:
   function getitnow() {

       echo $this->input->get('data');

   }

and when using the url


Code:
mydomain.com/test/getitnow?data=hello%20world

CI echoed 'Hello world' as a result

I use CI since 3 years and I know that but try to use CI with $config['uri_protocol'] = 'QUERY_STRING'; with my htaccess on a php fastcgi hosting, It doesn't work... Sad
Reply
#9

I use fcgid and use the same htaccess you are (with the ?), AND use query strings (and superglobal $_GET is available and populated). The only difference I see is I have mine set like:
PHP Code:
$config['uri_protocol']        = 'REQUEST_URI';

$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE//note I'm not using ?c=controller&m=method etc, just regular /controller/method urls 

I'm using CI 2.2
Reply
#10

OK, guys. I think I'm missing the point here.

The uri_protocol setting is used to tell CI which server global holds your URI string. So if your server needs you to set te uri_protocol to QUERY_STRING it should be fine, but it doesn't require you to use GET variables. You'll still use regular /controller/method URI's.
And why would you consider to set the enable_query_strings to true if not using the ?c=controller&m=method way of working...?

This maybe a strange question: But are you sure your server runs Apache server? I had some similar problems when trying to make things work on a server running NGINX...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB