-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_auth.php
41 lines (32 loc) · 915 Bytes
/
user_auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* Created by JetBrains PhpStorm.
* User: dan
* Date: 23/03/11
* Time: 20:27
* To change this template use File | Settings | File Templates.
*/
include('config.php');
function authenticate_user() {
header('WWW-Authenticate: Basic realm="SimplePlanet"');
header("HTTP/1.0 401 Unauthorized");
exit;
}
if (! isset($_SERVER['PHP_AUTH_USER'])) {
authenticate_user();
} else {
mysql_pconnect($dbserver,$dbusername,$dbpassword)
or die("Can't connect to DB server");
mysql_select_db($db)
or die("Can't select database");
$query = "SELECT username, pwd FROM logins
WHERE username='$_SERVER[PHP_AUTH_USER]' AND
pwd=MD5('$_SERVER[PHP_AUTH_PW]')";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
authenticate_user();
} else {
echo "Welcome " . $_SERVER["PHP_AUTH_USER"];
}
}
?>