Ok capito grazie a tutti molto utili.
EDIT: Non funziona più...eccovi i codici:
admin.php
Codice PHP:
<?php
if (isset($_SERVER['PHP_AUTH_USER'])) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pagina Amministratore</title>
<!-- Inizio Codice Standard Pagine -->
<link href="web/style.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="web/favicon.ico" />
<script type="text/javascript" src="js/protezione.js"></script>
<script type="text/javascript" src="js/status_bar.js"></script>
<script type="text/javascript" src="js/jserror.js"></script>
<!-- Fine Codice Standard Pagine -->
</head>
<body onload="welcometext()">
<p style="color:#00FFFF; font-size:10pt; font-family:'Comic Sans MS'">Benvenuto
Amministratore.</p>
<ul>
<li>
<p style="color:#00FFFF; font-size:10pt; font-family:'Comic Sans MS'">
<a title="E-mail iscritti alla newsletter" href="newsletter/iscritti/db.txt" style="text-decoration: none">
Iscritti Newsletter</a></p></li>
<li>
<p style="color:#00FFFF; font-size:10pt; font-family:'Comic Sans MS'">
<a title="Invia un messaggio agli iscritti della Newsletter" href="newsletter/admin.php" style="text-decoration: none">
Invia Messaggio di Newsletter</a></p></li>
<li>
<p style="color:#00FFFF; font-size:10pt; font-family:'Comic Sans MS'">
<a title="Genera la SiteMap per Miki92" href="sitemap/sitemap.php" style="text-decoration: none">
Genera SiteMap</a></p></li>
</ul>
</body>
</html>
<?php
}
else {
Header("Location: login.php");
}
?>
login.php
Codice PHP:
<?
$path = "db/admin.txt";
$file = file($path);
$user = array();
$pass = array();
for($i = 0; $i < count($file); $i++)
{
$dati = explode('|',trim($file[$i]));
$user[] = $dati[0];
$pass[] = $dati[1];
}
if (!isset($_SERVER['PHP_AUTH_USER']))
{
Header("WWW-Authenticate: Basic realm=\"Area Riservata\"");
Header("HTTP/1.0 401 Unauthorized");
exit;
}
else if (in_array($_SERVER['PHP_AUTH_USER'], $user) && in_array($_SERVER['PHP_AUTH_PW'], $pass))
{
echo "<script type=\"text/javascript\">alert('Grazie per esserti autenticato " . $_SERVER['PHP_AUTH_USER'] . "!')</script>";
echo "<script type=\"text/javascript\">history.go(-1)</script>";
}
else
{
echo "<script type=\"text/javascript\">alert('Login Incorretto si prega di riprovare.')</script>";
echo "<script type=\"text/javascript\">history.go(login.php)</script>";
}
?>
db/admin.txt