Discover script’s URL (or parts thereof)

Sample code:

$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['PHP_SELF'];
header("Location: http://$host$uri");

See $_SERVER in PHP Manual.

Sample code:



The URI which was given in order to access this page; for instance, '/index.html'. Compare it to $_SERVER['PHP_SELF'].

string basename ( string $path [, string $suffix ] )

Given a string containing the path to a file or directory, this function will return the trailing name component.

mixed pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] )

pathinfo() returns information about path: either an associative array or a string, depending on options.

// $page === 'index.html'
// Output === 'html'
$ext = pathfinfo($page, PATHINFO_EXTENSION);
echo $ext . PHP_EOL;

About samehramzylabib

See About on
This entry was posted in PHP and Filesystem, PHP Constants, PHP Form Processing, PHP Script Writing and tagged , . Bookmark the permalink.


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s