如何使 htaccess 中添加的查询字符串在 codeigniter 应用程序中可用?
我正在使用 CodeIgniter 开发 PHP 应用程序。通过代理访问该应用程序的人将可以访问该应用程序,该代理将向查询字符串添加一些信息。因此,如果用户请求以下内容: http://myapplication.com/main/,代理将自动转换在 http://myapplication.com/main/?user=userid 中。
请不要批评我用这种方式传递用户id,这是客户的要求,而不是我的! ;)
我对 CodeIgniter 的经验不是很丰富,但我知道它使用段而不是查询字符串,但我可以将其更改为查询字符串。问题是,我不想到处使用查询字符串。
问题是,我没有通过该代理工作,所以我想在本地计算机上模拟它。如果我在地址栏中手动输入:http://localhost/main/?user=12345,我可以使用 $_GET['user'] 获取它并在我的应用程序中使用它。但我希望所有请求都包含用户 ID,而无需手动添加。这就是我在 .htaccess 中所做的事情:
RewriteEngine on
RewriteCond $1 !^(index\.php|_|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1?user=12345 [L]
我的 .htaccess 工作正常,因为如果我在 index.php 文件中 print_r($_GET) ,信息就在那里。但如果我在 CI 控制器中尝试相同的操作,则 $_GET 数组为空。奇怪的是,正如我上面所说,如果我在浏览器的位置栏中手动键入它,则可以从我的控制器获得该信息。
谁能帮我找出是什么原因导致我在 .htaccess 中添加的查询字符串在 CI 控制器中不可用?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
你怎么检查呢?通过“$_GET 数组为空”如果是,我建议阅读 在 codeigniter 中启用 $_GET
Edit:
how you check it ? by "the $_GET array is empty" if yes I suggest to read Enabling $_GET in codeigniter