Welcome Guest, Not a member yet? Register   Sign In
$_GET
#1

[eluser]BradEstey[/eluser]
I need to be able to use Query Strings for 3 things:

- Track is a user came from Google Adwords (looking for $_GET['gclid'])
- Track search queries with Google Analytics (by assigning $_GET['q']
- Our CRM system sends data back to us through the URL.

I've set:

Code:
$config['enable_query_strings'] = TRUE;

But it does nothing. No matter what I try I always get "Undefined index: gclid".

I've narrowed the problem down to my .htaccess file RewriteRule but I don't know how to fix the problem. This is what my .htaccess file looks like:

Code:
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|robots\.txt|img/|css/|js/)
RewriteRule ^(.*)$ index.php?/$1 [L]

If I remove the question mark from last line then $_GET['gclid'] works, but if I go to a page like website.com/products?gclid=234234, uri_string() returns "gclid" instead of the actual page URI.

My current solution is just to use $_SERVER['REQUEST_URI'] instead of uri_string() and using a simple function to trim off the query strings.

Code:
$end = strrpos($uri, '?');
$uri = substr($uri, 1, ($end-1));
// Returns directory without leading slashes or query strings.

Is there a better solution or should I just stop expecting CI functions to do what $_SERVER variables already exist for?
#2

[eluser]danmontgomery[/eluser]
In config.php, change $config['uri_protocol'] to PATH_INFO instead of AUTO. That and enable_query_strings should be all you need... htaccess looks fine.
#3

[eluser]BradEstey[/eluser]
I tried running through all of the different uri_protocols to no avail. They all cause different issues with my URL rewriting stuff. I'm not using typical website.com/controller/value or whatever format. I confirm with my database whether a page exists or not and then choose the view accordingly. I only use routing to determine the controllers, but pretty much everything past the first URI segment is set to :any and passed through the database to determine if the page exists or not..

I have to do it this way because users with access to the CMS need to be able to rename pages whatever they want, so URLs aren't always logical.
#4

[eluser]cahva[/eluser]
Create a test controller just to see if the GET works so you can rule out routing.

This works atleast on FreeBSD + Linux with apache2(PHP as a module).
I have this as my setup with working GET:
Code:
$config['uri_protocol']    = "PATH_INFO";

$config['enable_query_strings'] = TRUE;

.htaccess:
Quote:RewriteCond $1 !^(sitemap\.xml\.gz|index\.php|favicon\.ico|assets|themes|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Your .htaccess is basically the same so I dont know.. (EDIT: at closer look it isnt. You have questionmark after your index. That could be it.) But try to create a test controller something like this:
Code:
class Test extends Controller {
    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->output->enable_profiler(TRUE);
    }
}

Then point your browser and try with get parameters for example:
http://yourdomain.com/test?foo=bar&foo2=bar2

I usually dont use routes unless I really have to so I dont know if that could affect get parameters. I use _remap method in controllers as I find that more convenient(for me).
#5

[eluser]cahva[/eluser]
Question mark is needed in when using cgi(I remebered that after posting). So its definately because of that. Unfortunately I dont know how to get GET working(with url like my previous post) with CGI. Seems impossible as rewrite is sending the question mark already and sending another one will break it.

If someone knows how to get GET working with CGI the same as PHP as a module, I would like to know also Smile
#6

[eluser]DJMOHNL[/eluser]
i am almost sure it has something to do with the mod_rewrite flag: [QSA] (Query String Append) but i am no .htaccess expert and find it very hard to understand.

(keep this one in mind):
(almost the) same problem here: http://ellislab.com/forums/viewthread/162407/

follow this one too..




Theme © iAndrew 2016 - Forum software by © MyBB