phpDocumentor lodel
[ class tree: lodel ] [ index: lodel ] [ all elements ]

Source for file class.authHTTP.php

Documentation is available at class.authHTTP.php

  1. <?php
  2. /**
  3.  * Fichier de la classe AuthHTTP
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  10.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  11.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  12.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  13.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  14.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  15.  *
  16.  * Home page: http://www.lodel.org
  17.  *
  18.  * E-Mail: lodel@lodel.org
  19.  *
  20.  * All Rights Reserved
  21.  *
  22.  * This program is free software; you can redistribute it and/or modify
  23.  * it under the terms of the GNU General Public License as published by
  24.  * the Free Software Foundation; either version 2 of the License, or
  25.  * (at your option) any later version.
  26.  *
  27.  * This program is distributed in the hope that it will be useful,
  28.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.  * GNU General Public License for more details.
  31.  *
  32.  * You should have received a copy of the GNU General Public License
  33.  * along with this program; if not, write to the Free Software
  34.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35.  *
  36.  * @author Sophie Malafosse
  37.  * @copyright 2006
  38.  * @licence http://www.gnu.org/copyleft/gpl.html
  39.  * @since Fichier ajouté depuis la version 0.8
  40.  * @version CVS:$Id:
  41.  */
  42.  
  43.  
  44. /**
  45.  * Classe permettant l'authentification HTTP
  46.  * 
  47.  * <p>Cette classe est utilisée pour l'authentification HTTP (basic)</p>
  48.  *
  49.  * @package lodel
  50.  * @author Ghislain Picard
  51.  * @author Jean Lamy
  52.  * @licence http://www.gnu.org/copyleft/gpl.html
  53.  * @version CVS:$Id:
  54.  * @since Fichier ajouté depuis la version 0.8
  55.  * @see auth.php
  56.  * @see loginHTTP.php
  57.  * @see src/edition/index.php
  58.  */
  59.  
  60. class AuthHTTP
  61. {
  62.     /**
  63.     * Login récupéré dans le header
  64.     * @var string 
  65.     */
  66.     var $login;
  67.  
  68.     /**
  69.     * Mot de passe récupéré dans le header
  70.     * @var string 
  71.     */
  72.     var $password;
  73.  
  74.     
  75.     /**
  76.     * 
  77.     * retourne un booléen : true si le login et le mot de passe sont récupérés,
  78.     * false sinon
  79.     * @return bool 
  80.     */
  81.     function getHeader()
  82.     {
  83.         $this->reset();
  84.         if (!headers_sent())
  85.         {
  86.             if (!isset($_SERVER['PHP_AUTH_USER']|| !isset($_SERVER['PHP_AUTH_PW']))
  87.             {
  88.                 // variables non initialisées
  89.                 return false;
  90.             }
  91.             elseif (isset($_SERVER['PHP_AUTH_USER']&& isset($_SERVER['PHP_AUTH_PW']))
  92.             {
  93.                 // récupère le login et le mot de passe
  94.                 $this->login = $_SERVER['PHP_AUTH_USER'];
  95.                 $this->password = $_SERVER['PHP_AUTH_PW'];
  96.                 return true;
  97.             }
  98.         }
  99.         return false;
  100.     }
  101.  
  102.     /**
  103.         * Renvoi du header avec demande d'authentification
  104.         *
  105.         * @return 
  106.         */
  107.     function errorLogin()
  108.     {
  109.         header('WWW-Authenticate: Basic realm="Authentification requise"');
  110.             header('HTTP/1.0 401 Unauthorized');
  111.         echo "L'accès à cette ressource requiert une authentification : veuillez entrer le nom d'utilisateur
  112.         et le mot de passe que vous utilisez sous Lodel";
  113.         exit;
  114.     }
  115.  
  116.     
  117.     /**
  118.     * initialisation des variables
  119.     */
  120.     function reset()
  121.     {
  122.         $this->login = '';
  123.         $this->password = '';
  124.     }
  125.  
  126.     /**
  127.     * Retourne dans un tableau le login et le mot de passe
  128.     *
  129.     * @return array 
  130.     */
  131.     function getIdentifiers()
  132.     {
  133.         return array(
  134.         "login" => $this->login,
  135.         "password" => $this->password);
  136.     }
  137.     
  138. }
  139.  
  140. ?>

Documentation generated on Thu, 24 Jul 2008 05:07:18 +0200 by phpDocumentor 1.4.0a2