Discover script’s URL (or parts thereof)


Sample code:

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

See $_SERVER in PHP Manual.


Sample code:

$docRoot = $_SERVER["DOCUMENT_ROOT"];
require_once("$docRoot/web/includes/header_footer.php");

$_SERVER['REQUEST_URI']

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;
Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in PHP and Filesystem, PHP Constants, PHP Form Processing, PHP Script Writing and tagged , . Bookmark the permalink.

Comment

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s