PATH_INFO, ORIG_PATH_INFO, APACHE and PHP
A little while back I was trying to make a router for my application which I had grouped into classes. So a url could be like this :
www.site.com/index.php/class_name/method?id=15
or
www.site.com/index.php/controller/action?id=15 in the MVC style
or
localhost/project/index.php/class_name/method?id=15
PHP MVC frameworks like codeigniter use urls like that.
Apache makes available a variable called PATH_INFO to PHP which stores
the portion of the url between script and query string that is /class_name/method
On Localhost
index.php
print_r($_SERVER)
shows :
[SERVER_SIGNATURE] => <address>Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch Server at localhost Port 80</address>
[SERVER_SOFTWARE] => Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /var/www/
[SCRIPT_FILENAME] => /var/www/project/index.php
[REMOTE_PORT] => 39733
[REQUEST_METHOD] => GET
[QUERY_STRING] => id=15
[REQUEST_URI] => /project/index.php/class_name/method?id=15
[SCRIPT_NAME] => /project/index.php
[PATH_INFO] => /class_name/method
[PATH_TRANSLATED] => /var/www/class_name/method
[PHP_SELF] => /project/index.php/class_name/method
Next using .htaccess to redirect localhost/project/class_name/method to localhost/project/index.php/class_name/method and again viewing the $_SERVER variable with url : localhost/project/class_name/method
shows :
[SERVER_SIGNATURE] => <address>Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch Server at localhost Port 80</address>
[SERVER_SOFTWARE] => Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /var/www/
[SCRIPT_FILENAME] => /var/www/project/index.php
[REMOTE_PORT] => 39734
[REDIRECT_QUERY_STRING] => id=15
[REDIRECT_URL] => /project/class_name/method
[REQUEST_METHOD] => GET
[QUERY_STRING] => id=15
[REQUEST_URI] => /project/class_name/method?id=15
[SCRIPT_NAME] => /project/index.php
[PATH_INFO] => /class_name/method
[PATH_TRANSLATED] => /var/www/class_name/method
[PHP_SELF] => /project/index.php/class_name/method
In both the above PATH_INFO is identical results , REQUEST_URI is different.
On Webserver
Now when the same code was put up on the webserver ::::
without .htaccess redirect , url like domain.com/project/index.php/class_name/method?id=15
shows :
[SERVER_SOFTWARE] => Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
[PATH_INFO] => /class_name/method
[PATH_TRANSLATED] => /home/celcscom/public_html/project/index.php
[QUERY_STRING] => id=15
[REDIRECT_STATUS] => 200
[REMOTE_ADDR] => 59.93.245.243
[REMOTE_PORT] => 60157
[REQUEST_METHOD] => GET
[REQUEST_URI] => /project/index.php/class_name/method?id=15
[SCRIPT_FILENAME] => /home/celcscom/public_html/project/index.php
[SCRIPT_NAME] => /project/index.php
[SERVER_ADDR] => 216.67.245.98
[SERVER_PORT] => 80
[PHP_SELF] => /project/index.php/class_name/method
PATH_INFO is same as localhost.
The difference came when using .htaccess redirect , the output
shows :
[SERVER_SOFTWARE] => Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
[QUERY_STRING] => id=15
[REDIRECT_QUERY_STRING] => id=15
[REDIRECT_STATUS] => 200
[REDIRECT_UNIQUE_ID] => SsI359hD9WIAAHMWpgEAAAAD
[REDIRECT_URL] => /project/class_name/method
[REQUEST_METHOD] => GET
[REQUEST_URI] => /project/class_name/method?id=15
[SCRIPT_FILENAME] => /home/celcscom/public_html/project/index.php
[SCRIPT_NAME] => /project/index.php
[SERVER_ADDR] => 216.67.245.98
[ORIG_PATH_INFO] => /class_name/method
[ORIG_PATH_TRANSLATED] => /home/celcscom/public_html/project/index.php
[PHP_SELF] => /project/index.php
PATH_INFO is missing but ORIG_PATH_INFO is there with the information PATH_INFO was supposed to have.
So the php code had to be changed to check for $_SERVER['ORIG_PATH_INFO'] when $_SERVER['PATH_INFO'] is absent
PATH_INFO relies on the Apache AcceptPathInfo Directive
Popularity: 8% [?]















