refactor
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Thu, 30 Dec 2004 08:39:01 +0000 (08:39 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:04 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-190

scripts/webredirect.php

index 9d56509..a27cbd3 100644 (file)
@@ -26,18 +26,16 @@ require("../include/xorg.inc.php");
 // la config d'apache impose la forme suivante pour REQUEST_URI :
 // REQUEST_URI = /prenom.nom(/path/fichier.hmtl)?
 list($username, $path) = preg_split('/\//', $_SERVER["REQUEST_URI"], 2, PREG_SPLIT_NO_EMPTY);
+$res = $globals->xdb->query(
+        "SELECT  redirecturl
+           FROM  auth_user_quick AS a
+     INNER JOIN  aliases         AS al ON (al.id = a.user_id AND (al.type='a_vie' OR al.type='alias' OR al.type='epouse'))
+          WHERR  al.alias = {?}", $username);
 
-$result = mysql_query("SELECT redirecturl FROM auth_user_quick AS a INNER JOIN aliases AS al ON (al.id = a.user_id AND (al.type='a_vie' OR al.type='alias' OR al.type='epouse')) where al.alias= '$username'");
-if ($result and list($url) = mysql_fetch_row($result) and $url != '') {
-       // on envoie un redirect (PHP met automatiquement le code de retour 302
-       if (!empty($path)) {
-           if (substr($url, -1, 1) == "/")
-               $url .= $path;
-           else
-               $url .= "/" . $path;
-       }
-       header("Location: http://$url");
-       exit();
+if ($url = $res->fetchOneCell()) {
+    $url = preg_replace('@/+$@', '', $url);
+    header("Location: http://$url/$path");
+    exit();
 }
 
 // si on est ici, il y a eu un erreur ou on n'a pas trouvĂ© le redirect