$_SERVER[‘PATH_INFO’] not working!

Written by leif. Posted in PHP, Programmering

<?php
if (isset($_SERVER['PATH_INFO'])) {
    $request_uri = trim($_SERVER['PATH_INFO'], '/');
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) {
    $request_uri = trim(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['ORIG_PATH_INFO']), '/');
} else {
    $request_uri = '';
}


echo "PATH_INFO = " . $_SERVER['PATH_INFO'] . "<br>"; 
echo "\$request_uri = ".$request_uri . "<br>";
echo "All server vars<br>";
echo "<pre>";
print_r($_SERVER);
echo "</pre>";
echo "tested with: http://localhost:8080/wordpress/leif.php/asd/qwe<br>";
echo "Output:<pre>";
echo "

PATH_INFO = /asd/qwe
$request_uri = asd/qwe
All server vars
Array
(
    [HTTP_HOST] => localhost:8080
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_CONNECTION] => keep-alive

    [HTTP_COOKIE] => wp-settings-1=editor%3Dhtml%26m5%3Do%26m6%3Do%26libraryContent%3Dbrowse%26posts_list_mode%3Dlist; wp-settings-time-1=1451339038; PHPSESSID=qjba1jj2elp7se3sno0h2f8al3
    [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7
    [HTTP_ACCEPT_LANGUAGE] => da-dk
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [PATH] => /Applications/wordpress-4.4-0/varnish/bin:/Applications/wordpress-4.4-0/sqlite/bin:/Applications/wordpress-4.4-0/php/bin:/Applications/wordpress-4.4-0/mysql/bin:/Applications/wordpress-4.4-0/apache2/bin:/Applications/wordpress-4.4-0/common/bin:/usr/bin:/bin:/usr/sbin:/sbin
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache
    [SERVER_NAME] => localhost
    [SERVER_ADDR] => ::1
    [SERVER_PORT] => 8080
    [REMOTE_ADDR] => ::1
    [DOCUMENT_ROOT] => /Applications/wordpress-4.4-0/apache2/htdocs
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] => /wordpress/
    [CONTEXT_DOCUMENT_ROOT] => /Applications/wordpress-4.4-0/apps/wordpress/htdocs/
    [SERVER_ADMIN] => you@example.com
    [SCRIPT_FILENAME] => /Applications/wordpress-4.4-0/apps/wordpress/htdocs/leif.php
    [REMOTE_PORT] => 58280
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => 
    [REQUEST_URI] => /wordpress/leif.php/asd/qwe
    [SCRIPT_NAME] => /wordpress/leif.php
    [PATH_INFO] => /asd/qwe
    [PATH_TRANSLATED] => /Applications/wordpress-4.4-0/apache2/htdocs/asd/qwe
    [PHP_SELF] => /wordpress/leif.php/asd/qwe
    [REQUEST_TIME_FLOAT] => 1473105419.688
    [REQUEST_TIME] => 1473105419
)

";
echo "</pre>";

?>