ok raga, ecco qui lo script che ho realizzato.
funziona benino ma ho bisogno di fare delle aggiunte. Capisco che sarebbe molto più semplice utilizzare un database tipo MySql ma purtroppo sono costretto ad utilizzare un file testo.
Ecco il codice dell'intero script:
ECCO IL FILE INDEX.PHP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
w3.org/TR/html4/…;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Pagina di login</title>
</head>
<body>
<form action="log_admin.php" method="post">
<table align="center" border="1">
<tr>
<td>Username</td>
<td><input type="text" name="usr"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="psw"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="entra"></td>
</tr>
</table>
</form>
</body>
</html>
ECCO IL FILE LOG.ADMIN.PHP
<?
session_start();
session_register('loggato','username');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
w3.org/TR/html4/…;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Verifica Dati</title>
</head>
<body>
<?
//connessione al database
$user = $_REQUEST['usr'];
$pass = $_REQUEST['psw'];
if( ($user!=""
and ($pass!=""
)
{
if(($user == 'admin') and ($pass == 'admin'))// per cambiare user name e password
$usato = true;
if($usato)
{
//creo le sessioni -loggato- & -username-
$_SESSION['loggato'] = true;
$_SESSION['username'] = $user;
}
else
{
//session loggato=false
$_SESSION['loggato'] = false;
}
if($_SESSION['loggato'] == true)//se la sessione loggato è true...viene fatto il redirect alla home
{
echo "<script language='javascript' type='text/javascript'>";
echo "location = 'rubrica.php';";
echo "</script>";
}
else
{
echo "Dati NON corretti!!!";
echo "<br><br><br>";
echo " <a class='titoloCen' href='javascript:history.back()'>CLICCA QUI: Ritorna alla pagina precedente e correggi!!!</a>";
}
}
else
{
echo "Campi Vuoti!!!";
echo "<br><br><br>";
echo " <a class='titoloCen' href='javascript:history.back()'>CLICCA QUI: Ritorna alla pagina precedente e correggi!!!</a>";
}
?>
</body>
</html>
ECCO IL FILE LOGOUT.PHP
<?
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
w3.org/TR/html4/…;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Logout</title>
</head>
<body>
<?
session_unregister("username"
;
session_unregister("loggato"
;
session_destroy();
echo "<script language='javascript' type='text/javascript'>";
echo "location = 'index.php';";
echo "</script>";
?>
</body>
</html>
ECCO IL FILE RUBRICA.PHP
<html>
<head>
<title>Rubrica</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<form method="post" action="scrivi.php" >
<table width="300" border="0" cellspacing="0" cellpadding="4">
<tr>
<td>nome</td>
<td><input name="nome" type="text" id="nome"></td>
</tr>
<tr>
<td>cognome</td>
<td><input name="cognome" type="text" id="cognome"></td>
</tr>
<tr>
<td height="34">telefono</td>
<td><input name="telefono" type="text" id="telefono"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Invia"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
ECCO INFINE IL FILE SCRIVI.PHP
<html>
<head>
<title>Rubrica</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$nome = $_REQUEST['nome'];
$cognome = $_REQUEST['cognome'];
$tel = $_REQUEST['telefono'];
$dati = $nome."#".$cognome."#".$tel."\n";
$fd=fopen("rubrica.txt","a"
;
fwrite($fd,$dati);
fclose($fd);
?>
<div align="center">
SCRITTURA ESEGUITA CORRETTAMENTE
<br><br><br>
<a href="rubrica.php" > INSERISCI NUOVAMENTE</a>
<br><br><br>
<a href="logout.php" > ESCI</a>
</div>
</body>
</html>
Lo script per ora si basa solo sull'inserimento di
NOME
COGNOME
TELEFONO
Io vorrei inserire anche:
NOME
COGNOME
TELEFONO
PASSWORD
CONFERMA PASSWORD
CARICAMENTO FILE IMMAGINE
Qualcuno può aiutarmi con la modifica del codice?
Ricordo che posso solo utilizzare un file testo...no database