Publico un sencillo ejemplo de código en PHP donde:

  • Se obtiene la URL completa de la página del script
  • Se parsea la URL obtenida

<?php

/**
 * Via:
 * http://dev.kanngard.net/Permalinks/ID_20050507183447.html
 *
 */

function getUrl() {
    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
    $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/") . $s;
    $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
    return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
}

function strleft($s1, $s2) {
    return substr($s1, 0, strpos($s1, $s2));
}

/**
 * Via:
 * http://www.seraphinux.com/index.php/71/2008/04/22/php-parsear-una-url/
 *
 */

$url = getUrl();

$datos = parse_url($url);
foreach ($datos as $key=>$value) {
    echo "$key: $value <br  >";
}

?>

Vía: dev.kanngard.net

Vía: Seraphinux