Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/10/2012, 09:58
Avatar de jlct
jlct
 
Fecha de Ingreso: abril-2012
Ubicación: Venezuela
Mensajes: 148
Antigüedad: 12 años, 1 mes
Puntos: 19
Respuesta: Autenticacion Http con PHP y Mysql

Buenos días indagando consegui un codigo que funciona!! pero ahora me mandaron a adaptarlo el codigo es el siguiente:

autenticacion.php
Código PHP:
<?
include("src/Principal.php"); //clase conexion y demas funciones
function validateUser () {


    
$user $_SERVER['PHP_AUTH_USER'];
    
$password Encriptar($_SERVER['PHP_AUTH_PW']);
    
    
$sql "SELECT Count(*) as Number FROM tusuarios WHERE cId_Usuario='" $user "' AND cPassword='" $password "'";
    
$query EjecutarSql($sql) or die(mysql_error());

    
$result mysql_fetch_array($query);
    
$NumberOfUsers $result['Number'];

    if (
$NumberOfUsers != 1) {
        
        
header('WWW-Authenticate: Basic realm="Site Administration Area"');
        
header('Status: 401 Unauthorized');
        
/* Special Header for CGI mode */
        
header('HTTP-Status: 401 Unauthorized');
    
        
?>
<html>
<head>
<title>Access Unauthorized</title>
</head>
<body>
<h1>Access to the requested page denied</h1>
You have been denied access to this page for entering an 
incorrect or non-exist username and password.<br><br>
Press 'Refresh' to retry the login procedure.
</body>
</html>
        <?php

        
exit;
    } 
}    

?>
Index.php
Código PHP:
 <?php require_once("autenticacion.php"); validateUser(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Autenticacion</title>
</head>

<body>
<h2>BIENVENIDO <?=$_SERVER['PHP_AUTH_USER']?></h2>
</body>
</html>
lo probe y funciona correctamente pero ahora me mandaron a hacer la autenticacion con el Active Directory y la verdad no tengo la mas minima idea de como adactarlo a este codigo.

Espero me puedan ayudar.