Path Issues & Server Variables & URI

Example: http://192.168.147.128:888/index.php/case/candytour/category.php?id=7

  • __FILE__
    Example: C:\www\wikirex.com\case\candytour\admin\file-manager.php
  • dirname(__FILE__)
    Example: C:\www\wikirex.com\case\candytour\admin 
  • dirname(dirname(__FILE__))
    Example: C:\www\wikirex.com\case\candytour 
  • str_replace ( ‘\\’, ‘/’, dirname (__FILE__) );
    Example: C:/www/wikirex.com/case/candytour/admin 
  • $_SERVER[‘HTTP_HOST’]
    Example: 192.168.147.128:888 
  • $_SERVER[‘PHP_SELF’]
    Example: /case/candytour/admin/file-manager.php
  • $_SERVER[“REQUEST_URI”]
    /index.php/case/candytour/category.php?id=7 

    Note: If the URL is using default page like xxx.com/rex/?test=true
    The result will be: /rex/?test=true
  • $_SERVER[“PATH_INFO”]
    /case/candytour/category.php?id=7 
  • basename($_SERVER[“REQUEST_URI”])
    category.php?id=7
  • $_SERVER[‘DOCUMENT_ROOT’]
    /home/150399/domains/XXX.com.tw/html
  • dirname($_SERVER[‘PHP_SELF’])
    Example: /case/candytour/admin
  • basename(__FILE__)
    Example: file-manager.php
  • basename(__FILE__, “.php”)
    Example: file-manager
  • DIRECTORY_SEPARATOR
  • $path_parts = pathinfo(‘/www/htdocs/inc/lib.inc.php’); (since PHP 5.2.0)
    echo $path_parts[‘dirname’], “\n”; // /www/htdocs/inc
    echo $path_parts[‘basename’], “\n”; // lib.inc.php
    echo $path_parts[‘extension’], “\n”; // php
    echo $path_parts[‘filename’], “\n”; // lib.inc
  • parse_url(‘http://192.111.123.128:888/case/appmt/admin/update.php?doctor=1&action=update’)
    [scheme] => http
    [host] => 192.111.123.128
    [port] => 888
    [path] => /case/appmt/admin/update.php
    [query] => doctor=1&action=update

PHP Server variables: http://php.net/manual/en/reserved.variables.server.php

 

Ultimate Solution to get file name with query string:

PHP:

HTML:

Get Current Full URL:

Append a new param to an URL:

Encode file name of an URL:

 

One thought on “Path Issues & Server Variables & URI

  1. stephen

    Hurrah, that’s what I was looking for, what a data! existing here at this webpage, thanks admin of this web site.

Comments are closed.