<?php // Get current protocol. $protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === 0 ? 'https://' : 'http://'; // Get current domain. $domain = $_SERVER['HTTP_HOST']; // Get current path to the current file. $path = $_SERVER['SCRIPT_NAME']; // Get current querystring. $queryString = $_SERVER['QUERY_STRING']; // Merge all the variables together. $url = $protocol . $domain . $path . "?" . $queryString; echo $url