Listing du fichier montresource.php
00001<?php
00002 # # (gH) -_- montresource.php ; TimeStamp (unix) : 25 Février 2026 vers 11:03
00003
00004 error_reporting(E_ALL | E_NOTICE ) ;
00005
00006 include("std.php") ;
00007
00008 ############################################################ 1
00009 #
00010 # pour des raisons de sécurité, il ne faut pas mettre
00011 # ce programme à la racine de votre site ou dans un
00012 # répertoire qui permettrait de voir des fichiers "sensibles"
00013 # (avec mot de passe, option de configuration...)
00014 #
00015 ############################################################ 2
00016
00017 debutPage("Code-source ","strict") ;
00018 debutSection("100%") ;
00019
00020 $aide = "oui" ;
00021 $txtaide = "Pour ne pas avoir les numéros de ligne, ajouter &nl=non à l'URL." ;
00022 $txtaide = "" ;
00023
00024 # sans paramètre, on affiche l'aide
00025
00026 if (isset($_GET["nomfic"])) {
00027 $fn = $_GET["nomfic"] ;
00028 $aide = "non" ;
00029 } ; # finsi
00030
00031 # affichage éventuel de l'aide
00032
00033 if ($aide=="oui") {
00034
00035 h2("Syntaxe : montresource.php?nomfic=".s_span("nom du fichier","gbleuf")) ;
00036 pvide() ;
00037 h3("Exemples :") ;
00038 blockquote() ;
00039 p() ;
00040 echo "- avec numéros de ligne : " ;
00041 echo href("montresource.php?nomfic=std.php","std.php") ;
00042 nbsp(5) ;
00043 echo href("montresource.php?nomfic=std.css","std.css") ;
00044 finp() ;
00045 p() ;
00046 echo "- sans numéros de ligne : " ;
00047 echo href("montresource.php?nomfic=std.php&nl=non","std.php&nl=non") ;
00048 finp() ;
00049 finblockquote() ;
00050
00051 finSection() ;
00052 finPage() ;
00053 return ;
00054
00055 } ; # fin si
00056
00057 # il faut vérifier qu'on ne remonte pas avec le nom du fichier
00058
00059 $li = 1 ;
00060 $nl = "" ;
00061 if (isset($_GET["nl"])) { $nl = $_GET["nl"] ; } ;
00062 if ($nl=="non") { $li = 0 ; } ;
00063
00064 $strp = strpos(" $fn","..") ;
00065 $strc = strpos(" $fn","./") ;
00066 $strr = strpos(" $fn","/") ;
00067 $strh = strpos(" $fn","http") ;
00068
00069 if (($strp) or ($strh) or ($strc) or ($strr) ) {
00070
00071 echo "Non ! La remontée avec .. ou http://... ou / est interdite." ;
00072 finSection() ;
00073 finPage() ;
00074 return ;
00075
00076 } ; # fin si
00077
00078 # puis il faut vérifier que le fichier existe
00079
00080 if (!file_exists($fn)) {
00081 h1("Fichier ".b("$fn")." introuvable.") ;
00082 finSection() ;
00083 finPage() ;
00084 return ;
00085 } ; # fin si
00086
00087 # arrivé ici, on peut afficher...
00088
00089
00090 $server = $_SERVER['SERVER_NAME'] ;
00091 h1("Listing du fichier $fn ") ;
00092 pvide() ;
00093
00094 sdl() ;
00095 cmt($txtaide) ;
00096 sdl() ;
00097 $typeFic = substr($fn,strrpos($fn,".")) ;
00098
00099 echo "\n<!-- listing de $fn mode numéro de ligne = $li -->\n\n" ;
00100 div() ;
00101
00102 /* inutile, suite au changement de version
00103
00104 if ($server == "localhost") {
00105 } else {
00106 echo showSourcePhpLeria($fn,$typeFic,$li) ;
00107 } ; # fin si
00108
00109 */
00110
00111 echo showSourcePhpGh($fn,$typeFic,$li) ;
00112
00113 findiv() ;
00114 echo "<!-- fin du listing de $fn -->\n\n" ;
00115
00116 p("texte") ;
00117 echo " Pour ne pas voir les numéros de ligne, ajoutez ".b("&nl=non")." à la suite du nom du fichier. " ;
00118 finp() ;
00119
00120 ############################################################
00121
00122 function showSourcePhpGh($chemin,$typeFic="txt",$nbLigne = 1) {
00123
00124 ############################################################
00125
00126
00127 if (file_exists($chemin)) {
00128 $str = highlight_file($chemin, TRUE);
00129 } else {
00130 return "Fichier ".b("$chemin")." introuvable." ;
00131 } ; # fin si
00132
00133 // Nettoyage du code
00134
00135 $str = str_replace("<code>", '', $str) ;
00136 $str = str_replace("</code>", '', $str) ;
00137
00138 $str = str_replace("<pre>", '', $str) ;
00139 $str = str_replace("</pre>", '', $str) ;
00140
00141 $str = preg_replace('/<span style="(.*)">(.*)<(.*)<\/span>/Um','<span style="\1">\2</span><\3',$str);
00142 $out = $str ;
00143
00144 // Explode sur le <br />
00145
00146 $str = str_replace("\n", '<br />', $str);
00147
00148 $arr = explode('<br />', $str);
00149 $nbe = count($arr) ;
00150 if ($nbe==1) {
00151 $arr = explode('\n', $str);
00152 $nbe = count($arr) ;
00153 } ; # fin si
00154
00155 $numLigne = 0 ;
00156 $out = "" ;
00157 foreach ($arr as $ligne){
00158 #$ligne = str_replace("\n", '', $ligne);
00159 #$ligne = str_replace("\r", '', $ligne);
00160 $numLigne++ ;
00161 if ($numLigne<$nbe) {
00162 if ($nbLigne==1) {
00163 $out .= '<span style="color:#000000">'.sprintf("%05d ",$numLigne)."</span>".snbsp(4) ;
00164 } ; # fin si
00165 $out .= $ligne ;
00166 $out .= " <br />\n";
00167 } else {
00168 $out .= "</span>\n" ;
00169 } ; # fin si on n'est pas à la dernière ligne
00170 } ; # fin pour chaque
00171
00172 $out = "<code>\n".$out."</code>\n";
00173
00174 return $out;
00175
00176 } # fin de fonction showSourcePhpGh
00177
00178 ############################################################
00179
00180 function showSourcePhpLeria($chemin,$typeFic="txt",$nbLigne = 1) {
00181
00182 ############################################################
00183
00184
00185 if (file_exists($chemin)) {
00186 $str = highlight_file($chemin, TRUE);
00187 } else {
00188 return "Fichier ".b("$chemin")." introuvable." ;
00189 } ; # fin si
00190
00191 // Nettoyage du code
00192
00193 $str = str_replace("<code>", '', $str) ;
00194 $str = str_replace("</code>", '', $str) ;
00195
00196 $str = preg_replace('/<span style="(.*)">(.*)<(.*)<\/span>/Um','<span style="\1">\2</span><\3',$str);
00197
00198 // Explode sur le <br />
00199
00200 $arr = explode('<br />', $str);
00201 $numLigne = 0 ;
00202 $nbe = count($arr) ;
00203 $out = "" ;
00204 foreach ($arr as $ligne){
00205 $ligne = str_replace("\n", '', $ligne);
00206 $numLigne++ ;
00207 if ($numLigne<$nbe) {
00208 if ($nbLigne==1) {
00209 $out .= '<span style="color:#000000">'.sprintf("%05d ",$numLigne)."</span>".snbsp(4) ;
00210 } ; # fin si
00211 $out .= $ligne." <br />\n";
00212 } else {
00213 $out .= "</span>\n" ;
00214 } ; # fin si on n'est pas à la dernière ligne
00215 } ; # fin pour chaque
00216 $out = "<code>\n".$out."</code>\n";
00217 return $out;
00218
00219 } # fin de fonction showSourcePhpLeria
00220
00221 finSection() ;
00222 finPage() ;
00223 ?>
Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.
Retour à la page principale de (gH)