简体   繁体   English

$ _REQUEST ['url]为空。 如何从$ _REQUEST ['url']获取控制器和方法? Bitnami WAMP

[英]$_REQUEST['url] is empty. How to get controller and methods from $_REQUEST['url']? Bitnami WAMP

( This question was modified two times, because of answers and other information i found. ) (由于发现了答案和其他信息,此问题已被修改两次。)

I need to get url from REQUEST. 我需要从REQUEST获取网址。 Below is the example of index.php where i try to print request,post and get - all of them are empty. 以下是index.php的示例,其中我尝试打印请求,发布和获取-所有这些都是空的。 I have tried this on my computer with Bitnami WAMP and in remote server (Arvixe). 我已经在使用Bitnami WAMP的计算机上和远程服务器(Arvixe)中尝试了此操作。 Because it does not work on the remote server, maybe the reason is in .htaccess? 因为它在远程服务器上不起作用,也许原因是在.htaccess中? Where else could be the reason that REQUEST['url'] is not working? REQUEST ['url']无法正常工作的其他原因是什么?

C:\\Bitnami\\wampstack-5.6.20-0\\apache2\\htdocs\\www\\Plan2own\\public\\index.php C:\\ Bitnami \\ wampstack-5.6.20-0 \\ apache2 \\ htdocs \\ www \\ Plan2own \\ public \\ index.php

<?php
error_reporting(E_ALL);
//phpinfo();
echo'<br> index.php   _GET  = **', var_dump( $_GET  ), '**';  
echo'<br> index.php   _POST  = **', var_dump( $_POST  ), '**';  
echo'<br> index.php GLOBALS[_REQUEST]  = **', var_dump($GLOBALS['_REQUEST']) , '**'; 
echo'<br> index.php   _REQUEST  = **', var_dump( $_REQUEST  ), '**';  
echo'<br> index.php   _REQUEST[url]  = **', var_dump( $_REQUEST['url']  ), '**';
echo'<br> index.php   _GET[url]  = **', var_dump( $_GET['url']  ), '**';  
echo'<br> index.php   _POST[url]  = **', var_dump( $_POST['url']  ), '**'; 

C:\\Bitnami\\wampstack-5.6.20-0\\apache2\\htdocs\\www\\Plan2own\\public.htaccess C:\\ Bitnami \\ wampstack-5.6.20-0 \\ apache2 \\ htdocs \\ www \\ Plan2own \\ public.htaccess

Options -MultiViews
Options -Indexes
RewriteEngine on
RewriteBase C:\Bitnami\wampstack-5.6.20-0/apache2/htdocs/www/Plan2own/public
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{ENV:REQUEST_FILENAME} !-d
RewriteCond %{ENV:REQUEST_FILENAME} !-f
RewriteCond %{ENV:REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

For example, using url http://plan2own/index.php/home i am getting the following results and empty url. 例如,使用URL http://plan2own/index.php/home我得到以下结果,并且URL为空。

index.php _GET = **array(0) { } **
index.php _POST = **array(0) { } **
index.php GLOBALS[_REQUEST] = **array(0) { } **
index.php _REQUEST = **array(0) { } **
index.php _REQUEST[url] = **NULL **
index.php _GET[url] = **NULL **
index.php _POST[url] = **NULL **

For example, using url http://plan2own/index.php?a=b i am getting empty url 例如,使用网址http://plan2own/index.php?a=b我得到的网址是空的

index.php _GET = **array(1) { ["a"]=> string(1) "b" } **
index.php _POST = **array(0) { } **
index.php GLOBALS[_REQUEST] = **array(1) { ["a"]=> string(1) "b" } **
index.php _REQUEST = **array(1) { ["a"]=> string(1) "b" } **
index.php _REQUEST[url] = **NULL **
index.php _GET[url] = **NULL **
index.php _POST[url] = **NULL **

The idea is that i should get home from http://plan2own/index.php/home , ie i should get controller and methods. 这个想法是我应该从http://plan2own/index.php/home ,即我应该获得控制器和方法。

I read http://stackoverflow.com/questions/5701588/why-is-request-empty (a) commenting out auto_globals_jit in php.ini and restarting apache did not help; 我阅读了http://stackoverflow.com/questions/5701588/why-is-request-empty )在php.ini中注释了auto_globals_jit并重新启动apache并没有帮助; (b) request_oder and variable_order in php.ini are correct in my case. (b)在我的情况下,php.ini中的request_oder和variable_order是正确的。

I am checking the correct php.ini file, which i can see using phpinfor(); 我正在检查正确的php.ini文件,使用phpinfor()可以看到该文件; in "Loaded Configuration File" line. 在“已加载的配置文件”行中。

Your question mentions auto_globals_jit and require_order . 您的问题提到了auto_globals_jitrequire_order Make sure variables_order in php.ini is set to something like: 确保php.ini variables_order设置为类似以下内容:

variables_order = "GPCS";

There should be nothing besides this text on that line. 在该行上,除了此文本外,没有任何其他内容。 ONce you've made a change to php.ini remember to restart PHP/the webserver. 一旦对php.ini进行了更改,请记住重新启动PHP / Web服务器。

Double-check that you're editing the correct php.ini file; 仔细检查您是否在编辑正确的php.ini文件; there are often several of them. 通常有几个。 If you execute phpinfo();exit; 如果执行phpinfo();exit; and in the output look at the path in Loaded configuration file , it should match the path of your php.ini 然后在输出中查看Loaded configuration file中的路径,它应与php.ini的路径匹配

Finaly, managed to get url in order to extract controller and method parameters using example from 最后,设法获取网址,以便使用示例中的示例提取控制器和方法参数

http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049 http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049

1) In C:\\Bitnami\\wampstack-5.6.20-0\\apache2\\htdocs\\www\\Plan2own\\public.htaccess change RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] to 1)在C:\\ Bitnami \\ wampstack-5.6.20-0 \\ apache2 \\ htdocs \\ www \\ Plan2own \\ public.htaccess中,将RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]更改为

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

2) which redirects url to index.php and when one can analyze it using the code below. 2)将网址重定向到index.php ,何时可以使用以下代码对其进行分析。

// C:\\Bitnami\\wampstack-5.6.20-0\\apache2\\htdocs\\www\\Plan2own\\public\\index.php $request = str_replace("/Plan2own/public/index.php/", "", $_SERVER['REQUEST_URI']); // C:\\ Bitnami \\ wampstack-5.6.20-0 \\ apache2 \\ htdocs \\ www \\ Plan2own \\ public \\ index.php $ request = str_replace(“ / Plan2own / public / index.php /”,“”,$ _SERVER ['REQUEST_URI']); echo' 回声'
index.php request = ', var_dump( $request ), ' '; index.php request = ',var_dump($ request),' ';

For url http://www.domain.com/public/index.php/home/some The result is index.php request = **string(9) "home/some" ** 对于url http://www.domain.com/public/index.php/home/some结果为index.php request = **string(9) "home/some" **

ps I could not get $_REQUEST['url'] , because for some reason .htaccess command RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] , which was working on Linux, is not working in Arvixe and Bitnami WAMP. ps我无法获得$_REQUEST['url'] ,因为某种原因.htaccess命令RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]在Linux上无法正常工作Arvixe和Bitnami WAMP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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