2015-10-08 1 views
0

Quelles sont les différences entre l'authentification HTTP et $ _SESSION pour authentifier l'utilisateur sur le formulaire de connexion?

HTTP,

<?php 
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] !== 'demo' || $_SERVER['PHP_AUTH_PW'] !== 'demo') { 

    header("WWW-Authenticate: Basic realm=\"Secure Page\""); 
    header("HTTP\ 1.0 401 Unauthorized"); 
    echo 'No soup for you'; 
    exit; 
} 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<title>Basic HTTP Authentication</title> 
</head> 
<body> 

<h1>Secure Page</h1> 

<p>This is a page with secure content...</p> 

</body> 
</html> 

SESSION,

ession_start(); 
if(isset($_POST['username']) && isset($_POST['password'])) 
{ 
    if(auth($_POST['username'], $_POST['password'])) 
    { 
     // auth okay, setup session 
     $_SESSION['user'] = $_POST['username']; 
     // redirect to required page 
     header("Location: index.php"); 
    } else { 
     // didn't auth go back to loginform 
     header("Location: loginform.html"); 
    } 
} else { 
    // username and password not given so go back to login 
    header("Location: loginform.html"); 
} 

Lequel est plus sûr?

Répondre

0

Je choisirais la version PHP car elle est plus sûre et plus facile à utiliser.