Ways to get current page url and title in PHP

you will get the URL by

'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']

or

$_SERVER['SCRIPT_URI']

might focus on some platforms.

the title is one thing the PHP program gives to the browser via HTML:

<html><head><title>title is here</title> ...

so it's not something you "get" unless of course you receive something in the DB and send to the browser.

Update... would you mean the title of page leading for your php file? (the consumer clicks that page to get at your php file.) for the reason that situation, you should use $_SERVER['HTTP_REFERER'] but it's not certain to contain data (but more often than not it'll).

Listed here are couple of super global variables to get url info:

$_SERVER['PHP_SELF'];
$_SERVER['REQUEST_URI'];
$_SERVER['SCRIPT_NAME']

$_SERVER['SCRIPT_NAME']

$_SERVER['SCRIPT_NAME'] is going to be same - /index.php. It's regardless of the particular URI ($_SERVER['REQUEST_URI']) accustomed to access the website.

Because it returns the particular script title, it fails provide additional path information that might be present. Therefore if the $_SERVER['REQUEST_URI'] is /index.php/big/directory/ then too the $_SERVER['SCRIPT_NAME'] is going to be same - /index.php.

$_SERVER['SCRIPT_NAME'] is supported on all platforms

$_SERVER['PHP_SELF']

This is actually the filename from the presently performing script, in accordance with the document root. However, unlike $_SERVER['SCRIPT_NAME'], it offers additional path information like $_SERVER['REQUEST_URI'] once the actual php file exists within the path. Then when the $_SERVER['REQUEST_URI'] is /index.php/big/directory/ then $_SERVER['PHP_SELF'] is going to be /index.php/big/directory/.

If however all of the URI's under http://www.example.com/ is planned to http://www.example.com/index.php, then, for instance, http://www.example.com/abc/def will return /index.php like $_SERVER['SCRIPT_NAME']. Observe that $_SERVER['REQUEST_URI'] information is overlooked with this request.

$_SERVER['REQUEST_URI']

You'll have entire url including query string vars.

Title from the page:

There's no built-in functionality to obtain title from the page, however, you should use the HTML Simple DOM to see the items in <h2.

Example:

$title = str_get_html('<title></title>');

Now, you should use $title however, you want. Go to the their website for more information about this.