2009/06/30

$_SERVER to get current URL

Checked PHP Manual,

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.

If you are using apache, check this page,

SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
SCRIPT_FILENAME=/u/rse/.www/index.html
SCRIPT_URL=/u/rse/
SCRIPT_URI=http://en1.engelschall.com/u/rse/

In my server, I can use below code to get URL without query string (or ‘?q=’).

$url = getenv("SCRIPT_URI");
//or
$url = $_SERVER['SCRIPT_URI'];

No comments:

Post a Comment