28. april 2000 - 11:37
Der er
3 kommentarer og
1 løsning
Kunde login
Jeg har i timevis siddet og leddet efter et system, hvor man kan indtaste et bruger navn og et kode ord.. Og hvorefter om dette er rigtigt kan se en side!!!!
Det skal bruges til et kundelogin, så der skal kunne være flere forskellige kunder med hver deres password.. og en side til hver bruger/password!
Det lyder måske meget uoverkommeligt, men jeg har siddet og surfet rundt efter et sådan script i snart 2 timer nu, og unden resultat!
Håber der er en flittig sjæl der kan hjælpe!
/Alive
28. april 2000 - 13:38
#3
<?
//$Header: /cvs/cvsroot/timesheet/auth-lib.php,v 1.2 1999/03/27 21:04:53 kovacsp Exp $
/*
+----------------------------------------------------------------------+
| Auth-lib.php - Functions to authenticate remote WWW users |
+----------------------------------------------------------------------+
| Copyright (c) Peter D. Kovacs <kovacsp@egr.uri.edu> |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation; either version 2 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
+----------------------------------------------------------------------+
*/
/*
Example Usage:
Simply put <? include auth-lib.php; auth("MyRealm",##) ?> at the very
beginning of any document that you wish to protect.
"MyRealm" is the realm of the document. A given password is good for a
Combination of the following: a remote server, and a realm. By changing
the realm of a document it will cause the browser to reask for authentication.
## is an integer security level. A user with a certain security level can
access any document with a level less than or equal to their security level.
The default security level is 1.
*/
require "common.inc";
function authenticate($realm,$level=1) {
Header("WWW-authenticate: basic realm=\"$realm\"");
Header("HTTP/1.0 401 Unauthorized");
?>
<HTML>
<TITLE>Authorization for <? echo("$realm level-$level"); ?></TITLE>
<BODY>
You need a valid username/password to proceed.<br>
Contact <A HREF="mailto:mike.hellers@4thwave.lu">mike.hellers@4thwave.lu</A> if you think this shouldn\'t be happenning.
</BODY>
<HTML>
<?exit;
}
function auth($realm, $level=1) {
global $PHP_AUTH_USER;
global $PHP_AUTH_PW;
global $DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_DB;
if (!isset($PHP_AUTH_USER)) {
authenticate($realm,$level);
} else {
$dbh = dbConnect();
$id = strtolower($PHP_AUTH_USER);
list($qh,$num) = dbQuery("select password as passwd1, password('$PHP_AUTH_PW') as passwd2, level as authlevel, allowed_realms ".
"from user where username='$id'");
$data = dbResult($qh);
if (($data[passwd1] != $data[passwd2]) or ($data[authlevel] < $level)) {
authenticate($realm,$level);
} elseif (!ereg("${data[allowed_realms]}",$realm)) {
authenticate($realm,$level);
} else {
list($qh,$num) = dbQuery("update user set status='IN' where username='$id'");
return 1;
}
}
}
?>