¡Hola gente!
Hace muy poco, me encontré con una situación en la que tenía que obtener la URL desde la que se estaba ejecutando el script. El siguiente código obtiene, tal como el original, además de la url, los parámetros GET. La diferencia con éste es que nos permite eliminar uno o varios parámetros GET.
function getCurrentUrl($exceptions) { /* * @param array $exceptions an array containing the string keys of get to be skipped */ $pageURL = 'http'; if ($_SERVER ["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER ["SERVER_PORT"] != "80") { $pageURL .= $_SERVER ["SERVER_NAME"] . ":" . $_SERVER ["SERVER_PORT"] . $_SERVER ["REQUEST_URI"]; } else { $pageURL .= $_SERVER ["SERVER_NAME"] . $_SERVER ["REQUEST_URI"]; } foreach($exceptions as $e) { $e = preg_quote($e); $pageURL = preg_replace('/(?<=(&|\?))'.$e.'=.*?(&|$)/', "", $pageURL); } return $pageURL; }
¡Espero que les sea de utilidad!
Un saludo,
Pedro