2URL de la page courante
Publié le 27/09/2007 PHP
<?php if ($_SERVER['QUERY_STRING']) { // Look for Query to kill it // Remove 1 to kill interrogation point $webpath=substr($_SERVER['REQUEST_URI'],0, strpos ($_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING'])-1); } $self_url = sprintf('http%s://%s%s', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': ''), $_SERVER['HTTP_HOST'], $webpath); echo $self_url; ?>Ce code retourne http(s)://serveur.domaine.tld/dir/fichier.php
De plus, si il n'y a pas de fichier, il renvoie bien le répertoire