info:myphp:identification

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
info:myphp:identification [2018/07/18 09:45] – ↷ Page déplacée de info:git:homepage:myphp:identification à info:myphp:identification radeffinfo:myphp:identification [2026/03/05 09:51] (Version actuelle) radeff
Ligne 1: Ligne 1:
-identification.php+====== PHP authentification / authentication / identification ====== 
 +===== identification-fake-apache-authentication ===== 
 + 
 + 
 +<code> 
 +<?php 
 +/* fake htaccess authentication  
 +Fred Radeff (aka FR), radeff@akademia.ch, radeff.red, 21.02.2007 
 +adapted from: http://www.grappa.univ-lille3.fr/polys/reseaux-2004/reseaux020.html 
 + 
 +note: 
 +if you want to keep a trace of the logins, put a file login.txt 
 +in the same directory, which will be writable by the webserver or chmod 777 
 +and uncomment lines after "//authentication ok, keep a trace in file login.txt" 
 +*/ 
 + 
 +/*restricted user list (login/password) */ 
 +$liste=array( 
 +"toto/toto", 
 +"mao.zedong@china.com/manifest", 
 +"fred/fred" 
 +); 
 +  #create table from array $liste 
 +    for ($i=0;$i<count($liste);$i++) { 
 +      $l=explode("/",trim($liste[$i])); 
 +      $user[$i]=$l[0];  
 +      $pass[$i]=$l[1];  
 +    } 
 +    $nbusers=count($liste); 
 +    //check ID 
 +    $ok=-1; //start with no ID 
 +    for ($i=0;$i<$nbusers;$i++) { 
 +      if (($_SERVER['PHP_AUTH_USER']==$user[$i]) && ($_SERVER['PHP_AUTH_PW']==$pass[$i])) { 
 +        //USER ok, keep id 
 +        $ok=$i; 
 +      } 
 +    } 
 + //if check KO, $ok is still -1 
 +    //ask login+password 
 +    if ($ok==-1) { 
 + header("WWW-Authenticate: Basic realm='Restricted Area'"); 
 + print("<H1>Authorization Required</H1>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.<hr>"); 
 + exit;       
 +    } 
 +    //authentication ok, keep a trace in file login.txt 
 +//uncomment if you want to keep a trace 
 +/* $filename = 'login.txt'; 
 +if (!$handle = fopen($filename, 'a')) { 
 +         echo "Impossible d'ouvrir le fichier ($filename)"; 
 +         exit; 
 +   } 
 + $somecontent = $_SERVER['PHP_AUTH_USER'] .";" .date("Y-m-d h:i:s") ."\n"; 
 + fwrite($handle, $somecontent); 
 + fclose($handle); 
 +*/ 
 +/*OK end authentication */ 
 + 
 +?> 
 +</code> 
 + 
 +===== identification ===== 
 <code> <code>
 <? <?
  • info/myphp/identification.1531899942.txt.gz
  • Dernière modification : 2018/07/18 09:45
  • de radeff