PHP Snippets

Get The Current Page URL

Andrei Surdu Andrei Surdu ·

This function returns the current page URL. It concatenates the server’s host name and the request URI from PHP’s superglobal $_SERVER array. This function is useful for generating links to the current page, or for logging or debugging purposes.

PHP Function:

function getCurrentPageURL() { return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; }

// Example
// echo getCurrentPageURL();

Comments

Share your thoughts and join the conversation

Loading comments...

Leave a Comment

Your email will not be published

Comments are moderated and will appear after approval

0/2000