Restriction d’accès simple en PHP

d’après la source : forum.pluxml.org/viewtopic.php?id=1873

<?php
if ( !isset($_SERVER['PHP_AUTH_USER'])
	|| !isset($_SERVER['PHP_AUTH_PW'])
	|| ($_SERVER['PHP_AUTH_USER'] !== 'toto' )
	|| ($_SERVER['PHP_AUTH_PW'] !== 'passe') )
{
	header('WWW-Authenticate: Basic realm="Identification :"');
	header('HTTP/1.0 401 Unauthorized');
	echo '<html><head>';
	echo '<title>Acc&egrave;s Refus&eacute</title></head><body>';
	echo '<h1>Acc&egrave;s Refus&eacute</h1>';
	echo '</body>';
	exit;
}
?>

voir aussi : php.net/manual/fr/features.http-auth.php

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *