Start New Discussion within our Web Development Community
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 } else {
 return $pageURL;
  echo curPageURL();

<!-- Sometimes it is needed to get the page name only. The following example shows how to do it: -->
function curPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

echo "The current page name is ".curPageName();

The above code displays the current url and extract the filename from the url

Also look into the manual for substr function

what i meant is getting the certain part a url from a string after a user inputs it, sorry for not mentioning earlier.


A more suitable method to look at might be parse_url.

Specifically, to get the host name out of a URL you would use:

$strUserUrl = '';
$strHost = parse_url($strUserUrl, PHP_URL_HOST);
// $strHost =

Or you could use the method without specifying a single component and it'll return an array breakdown of the URL.


This article has been dead for over six months. Start a new discussion instead.