简体   繁体   中英

How can I make a querystring added in htaccess available in codeigniter application?

I'm working on a PHP application using CodeIgniter. The application will be accessible for people who are accessing it through a proxy that will add some information to the querystring. So if a user request the following : http://myapplication.com/main/ , the proxy will automatically transform that in http://myapplication.com/main/?user=userid .

Please don't criticize me on that way to pass the user id, it's the client's request to do it like that, not mine! ;)

I'm not very experienced with CodeIgniter, but I know enough to know that it uses segments instead of querystring but I can change it to querystring. The thing is, I don't want to use querystring everywhere.

The thing is, I'm not working through that proxy, so I want to simulate that on my local computer. If I enter manually in the location bar : http://localhost/main/?user=12345 , I can get it and use it in my application using $_GET['user']. But I want the user id on all requests, without having to add it manually. So here's what I did in my .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|_|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1?user=12345 [L]

My .htaccess is working fine because if I print_r($_GET) in my index.php file, the information is there. But if I try the same from my CI controller, the $_GET array is empty. The weird thing is, as I said above, if I type it manually in the browser's location bar, the information is available from my controller.

Can anyone help me figure out what causes my querystring added in .htaccess to be unavailable in my CI controllers?

Thanks!

RewriteRule ^(.*)$ /index.php/?user=12345&$1 [L]

Edit: how you check it ? by "the $_GET array is empty" if yes I suggest to read Enabling $_GET in codeigniter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM