Showing posts with label PHP Get Current Page URL. Show all posts
Showing posts with label PHP Get Current Page URL. Show all posts

Friday, 5 October 2018

PHP - GET CURRENT PAGE URL

This PHP snippet comes handy when post login you have to redirect user to the same page which he was browsing earlier.
Syntax

Wednesday, 3 June 2015

PHP Get Current URL

Get the current URL. Use it with social widgets that require the web page's URL 
<?php
function get_current_url($full = true)
{
 if (!$full) return $_SERVER['REQUEST_URI'];
 return 'http'.(isset($_SERVER['HTTPS']) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].(($_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443) ? '' : ':'.$_SERVER['SERVER_PORT']).$_SERVER['REQUEST_URI'];
}
?>

Usage

To get the full URL, including the domain part:

echo get_current_url();

To get just the URL for internal use:

echo get_current_url(false);


This function will also work for HTTPS and non-standard ports.