PHP How to Get the Current Page URL - php database - Phptpoint.com

How to Get the Current Page URL

/ins>

Get the Current Page URL

With the help of this tutorial page, you can see the Current Page URL.

Sometimes, you might want to get the current page URL that is shown in the browser URL window.

For example if you want to let your users submit a comment on any post, you want to get that same exact URL.

Here is how you can do that.

Add the following code to a page:

Now see the current page url using currentPageURL() function

In the given above example
Define a function named currentPageURL( ). Create a variable $PageURL with value “http”. Now, with the help of Super Global Variable $_SERVER[‘https’] checked server is secure server or not.Used Global variable $_SERVER[“SERVER_PORT”] which returns the current port of the server, Now checked if the port number is 80, it means server is local server, then displayed the server name using $_SERVER[“SERVER_NAME”] and page url using $_SERVER[“REQUEST_URI”] and assign the values inside $PageURL variable.
$PageURL variable returns the server name, server port and server url.
Call the function currentPageURL( ) to display the current page URL.