password home page in php?
ciao: copio questo inserimento,perche cercando di farmi rispondere nel forum dove l'ho copiato, in fase di inserimento mi veniva detto che non poteva essere inviato perche troppo corto,l'ho allungato ma mi dava il solito errore. ciao: io ho costruito un sito,devo crearlo in html (index.html) e poi inserire il codice php per fare in modo che chi accede al sito deve immetere una password?. praticamente devo creare la prima pagina in html,inserire le sezzioni per mettere nome, password?, poi creare una seconda pagina dove far accedere chi mette nome, password?. è difficile studiare il php? io uso dreamweaver S3,però non è che fa tutto. :?:
grazie
Script composto da 5 pagine ..
Creato da Guido8975...
Autenticazione utente pagina protetta!!
Citazione:
Pagina 1 login.htm
Codice HTML:
<html>
<head>
<title>Pagina di Login</title>
</head>
<body>
<form method=POST action=login.php>
<input type=text name=user size=20>
<input type=password name=pass size=20>
<input type=submit value=Login>
<input type=reset value=Reset></form>
</body>
</html>
Citazione:
Pagina 2 login.php
Codice PHP:
<?
session_start();
include 'conf.php';
$user= $_POST['user'];
$pass= $_POST['pass'];
if((!$user) || (!$pass)){
echo "Inserire tutte le informazioni!";
header("Location: login.htm");
}else{
if($user==$usern && $pass==$passw){
$_SESSION['username'] = $usern;
header("Location: protetta.php");
}else{
header("Location: login.htm");
}
}
?>
Citazione:
Pagina 3 conf.php
Codice PHP:
<?
$usern= 'pippo';// username
$passw= 'pipo';// password
?>
Citazione:
Pagina 4 logout.php
Codice PHP:
<?php
include 'conf.php';
session_start();
if ($username==$usern) {
session_unset();
session_destroy();
echo "Hai effettuato il log out!!";
} ?>
Citazione:
Pagina 5 protetta.php
Codice PHP:
<?php
include 'conf.php';
session_start();
if ($username==$usern) { ?>
Contenuto pagina html<br>
Codice HTML:
<a href=logout.php>Log OUt</a>
<? } ?>
funziona ma non è protetto?
ciao: grazie mille funziona alla perfezione. bravissimo,girando molti forum tra cui io programmo,nessuno c'è riuscito ne ho girati molti sei stato l'unico ottimo!
prima pagina index.html
Codice HTML:
<html>
<head>
<title>Pagina di Login</title>
</head>
<body>
<form method=POST action=home.php>
nome: <input type=text name=user size=20><br>
password: <input type=password name=pass size=20><br>
<input type=submit value=invia>
<input type=reset value=reimposta></form>
</body>
</html>
seconda pagina home.php
Codice HTML:
<?php
$nick = $_POST['user'];
$pass = $_POST['pass'];
?>
<html>
<head><title>Home</title></head>
<body>
<?php
if($nick=="prova" && $pass=="prova"){
echo "TI SEI LOGGATO CON SUCCESSO!<br>ORA SEI NELLA SEZIONE PRIVATA DEL SITO";
} else{
echo "SPIACENTE, MA NON SEI RIUSCITO AD ACCEDERE ALLA SEZIONE PRIVADA DEL SITO!<br>RICONTROLLA I DATI!";
}
?>
</body>
</html>