简体   繁体   中英

$_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. Below is the example of index.php where i try to print request,post and get - all of them are empty. I have tried this on my computer with Bitnami WAMP and in remote server (Arvixe). Because it does not work on the remote server, maybe the reason is in .htaccess? Where else could be the reason that REQUEST['url'] is not working?

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

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.

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

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.

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; (b) request_oder and variable_order in php.ini are correct in my case.

I am checking the correct php.ini file, which i can see using phpinfor(); in "Loaded Configuration File" line.

Your question mentions auto_globals_jit and require_order . Make sure variables_order in php.ini is set to something like:

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.

Double-check that you're editing the correct php.ini file; there are often several of them. If you execute phpinfo();exit; and in the output look at the path in Loaded configuration file , it should match the path of your 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

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

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

2) which redirects url to index.php and when one can analyze it using the code below.

// 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 ), ' ';

For url http://www.domain.com/public/index.php/home/some The result is 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.

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