Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']?

Tags:

php

apache

What’s the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? How do I use them?

When I run print_r($_SERVER), PATH_INFO and ORIG_PATH_INFO are not present in the array. Why not? How can I enable them?

I have read the PHP manual on them, but still don’t understand them.

like image 361
zhuanzhou Avatar asked Apr 12 '11 02:04

zhuanzhou


People also ask

What is $_ server [' Php_self ']?

Description. $_SERVER['PHP_SELF'] Returns the filename of the currently executing script. $_SERVER['GATEWAY_INTERFACE'] Returns the version of the Common Gateway Interface (CGI) the server is using.

What is $_ server [' Request_uri ']?

$_SERVER['REQUEST_URI'] contains the URI of the current page. So if the full path of a page is https://www.w3resource.com/html/html-tutorials.php, $_SERVER['REQUEST_URI'] would contain /html/html-tutorials. php. Following php code used $_SERVER['REQUEST_URI'] variable.

What is $_ server [' Document_root ']?

DOCUMENT_ROOT in PHP $_SERVER contains information about the document root directory under which the current script is executing. It is accessible via the variable DOCUMENT_ROOT , as defined in the server's configuration file. This is the path where your application code is stored.

What is Path_info?

The PATH_INFO variable specifies a path to be interpreted by the CGI script. It identifies the resource or sub-resource to be returned by the CGI script, and is derived from the portion of the URI path hierarchy following the part that identifies the script itself.


2 Answers

The PATH_INFO variable is only present if you invoke a PHP script like this:

http://www.example.com/phpinfo.php/HELLO_THERE

It's only the /HELLO_THERE part after the .php script. If you don't invoke the URL like that, there won't be a $_SERVER["PATH_INFO"] environment variable.

The PORIG_ prefix is somewhat uncommon. PATH_INFO is a standard CGI-environment variable, and should never be prefixed. Where did you read that? (There were some issues around PHP3/PHP4 if you invoked the PHP interpreter via cgi-bin/ - but hardly anyone has such setups today.)

For reference: http://www.ietf.org/rfc/rfc3875

like image 162
mario Avatar answered Oct 21 '22 14:10

mario


try this :

$path_info = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : '');
like image 30
dhamaso Avatar answered Oct 21 '22 15:10

dhamaso