-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.php
38 lines (30 loc) · 1.04 KB
/
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
<?php
session_start();
if($_SERVER['SERVER_NAME']!="localhost"){
//aquesta part necessita fitxer .htaccess següent:
/*
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
*/
list($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']) =
explode(':',base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'],6)));
}
/*autentificació*/
$valid_passwords=array(
"admin"=>"icra123",
);
$valid_users = array_keys($valid_passwords);
$user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : false;
$pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : false;
$validated = (in_array($user, $valid_users)) && ($pass==$valid_passwords[$user]);
if(!$validated){
/*
*/
header('WWW-Authenticate: Basic realm="paretverda.icradev.cat"');
header('HTTP/1.0 401 Unauthorized');
die("error: usuari i/o password incorrectes");
}
//si arriba aquí és usuari vàlid, pots carregar la pàgina
//fes servir SESSION
$_SESSION["auth"]=true;
?>