473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to get controller and methods from $_REQUEST['url] ?

103 100+
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

Expand|Select|Wrap|Line Numbers
  1.    <?php
  2.     error_reporting(E_ALL);
  3.     //phpinfo();
  4.     echo'<br> index.php   _GET  = **', var_dump( $_GET  ), '**';  
  5.     echo'<br> index.php   _POST  = **', var_dump( $_POST  ), '**';  
  6.     echo'<br> index.php GLOBALS[_REQUEST]  = **', var_dump($GLOBALS['_REQUEST']) , '**'; 
  7.     echo'<br> index.php   _REQUEST  = **', var_dump( $_REQUEST  ), '**';
  8. echo'<br> index.php   _REQUEST[url]  = **', var_dump( $_REQUEST['url']  ), '**'; 
  9. echo'<br> index.php   _GET[url]  = **', var_dump( $_GET['url']  ), '**';  
  10. echo'<br> index.php   _POST[url]  = **', var_dump( $_POST['url']  ), '**'; 
C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\Plan2own\public\.htaccess
Expand|Select|Wrap|Line Numbers
  1.     Options -MultiViews
  2.     Options -Indexes
  3.     RewriteEngine on
  4.     RewriteBase C:\Bitnami\wampstack-5.6.20-0/apache2/htdocs/www/Plan2own/public
  5.     RewriteCond %{ENV:REDIRECT_STATUS} ^$
  6.     RewriteCond %{ENV:REQUEST_FILENAME} !-d
  7.     RewriteCond %{ENV:REQUEST_FILENAME} !-f
  8.     RewriteCond %{ENV:REQUEST_FILENAME} !-l
  9.     RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
  10.  
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 , i.e. 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.
Jul 24 '16 #1
1 1739
gintare
103 100+
Finally, managed to get url in order to extract controller and method parameters using example from to get url for subsequent analysis in order to extract controller and method paramters using example from
http://code.tutsplus.com/tutorials/u...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
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^(.*)$ index.php?/$1 [L]
2) which redirects url to index.php and when one can analyze it using the code below.
Expand|Select|Wrap|Line Numbers
  1. // C:\Bitnami\wampstack-5.6.20-0\apache2\htdocs\www\Plan2own\public\index.php 
  2. $request  = str_replace("/Plan2own/public/index.php/", "", $_SERVER['REQUEST_URI']);
  3.  echo'<br> index.php   request  = **', var_dump( $request  ), '**'; 
For url
Expand|Select|Wrap|Line Numbers
  1.  http://www.domain.com/public/index.php/home/some
The result is
Expand|Select|Wrap|Line Numbers
  1. index.php request = **string(9) "home/some" **

p.s. I could not get $_REQUEST['url'], because for some reason .htaccess command
Expand|Select|Wrap|Line Numbers
  1.  RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
, which was working on Linux, is not working in Arvixe and Bitnami WAMP.
Jul 24 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dinçer | last post by:
Hello, I am trying to call a simple web service from .net environment. The service gets an array parameter. When I run it, it becomes the error: Server was unable to process request. --> Array...
3
by: Dean Slindee | last post by:
I want to build an array on the fly in code with a parameter passed for the number of elements in the array. I am trying to do this by looping, but get an array with just one element in the end....
0
by: Dinçer | last post by:
Hello, I am trying to call a simple web service from .net environment. The service gets an array parameter. When I run it, it becomes the error: Server was unable to process request. --> Array...
0
by: Markus Ernst | last post by:
Hi In an application installed with PHP5 it looks like ftp_nlist() returns false if the directory is empty, instead of an empty array as it should according to the manual. On the original server...
2
by: Rohan | last post by:
how would i remove the empty array this is my function Private Function FindMeter(ByVal txt As String) As MeterAccountName Dim TempTxt(3) As String TempTxt = Strings.Split(Trim(Right(txt,...
0
by: dani.meier | last post by:
Hi I have a webservice which takes an Array as input. This Array is nullable and a null-array is treated different than an empty one. My propblem is now, that if I pass a null-array to the...
1
by: iwl | last post by:
Hi, I've tryed to save some data containing empty arrays (array('f')) in a shelve. It looks like the shelve has some problems with empty arrays, get allways: TypeError: ("'NoneType' object is...
3
by: swapnaoe | last post by:
Hi all, An empty array declared in a called function is used as a pointer to hold the address of an object passed in the calling function. this is perfectly legal. {/*calling function*/ ......
2
by: sarandnl08 | last post by:
Hi all, I can't find any problem in this program, i getting empty string as output, why? what happening here any one help? int main() { char *p1=“name”; char *p2; ...
1
by: Mladen Mavrovic | last post by:
This code returns 1 with print_r($urls) $pattern = '#^http://domain.com/(.*)(\w*)0\b#'; preg_match_all($pattern, $email, $urls); same code returns empty array with those two outputs: 1....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.