note 35308 added to features.http-auth

From: Date: Wed, 27 Aug 2003 05:35:16 +0000
Subject: note 35308 added to features.http-auth
Groups: php.notes 
Request: Send a blank email to php-notes+get-55155@lists.php.net to get a copy of this message
Sistema de login super simples vendo se tem ou não o usuario e senha no arquivo user.txt user.txt usuario:senha #------------------------------- renan:teste php:net #------------------------------- auth.php #------------------------------- <?php function buildUsers($file) { $linhas = file($file); foreach ($linhas as $linha) { $slice = explode(":", $linha); $array[$slice[0]] = substr($slice[1], 0, strlen($slice[1]) - 1); } return $array; } if (!isset($_SERVER['PHP_AUTH_USER'])) { header("WWW-Authenticate: Basic realm=\"PHP Auth\""); header("HTTP/1.0 401 Unauthorized"); echo "Erro 401: Você não tem autorização para visualizar essa página"; exit; } else { $users = buildUsers("user.txt"); if ($users[$_SERVER['PHP_AUTH_USER']] == $_SERVER['PHP_AUTH_PW']) { print "Olá {$_SERVER['PHP_AUTH_USER']}, seja bem vindo!<br>\nVocê esta dentro"; } else { header("WWW-Authenticate: Basic realm=\"PHP Auth\""); header("HTTP/1.0 401 Unauthorized"); echo "Erro 401: Você não tem autorização para visualizar essa página"; exit; } } ?> #------------------------------- É isso ai, simples não? Renan Gonçalves Brasil ---- Manual Page -- http://www.php.net/manual/en/features.http-auth.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35308 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35308&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35308&report=yes

« previous php.notes (#55155) next »