3E SIA: Pagina protetta (con le sessioni) in Php senza database

LEZIONE DEL 31 MARZO 2022 - CLASSE 3E SIA

Gestione delle pagine protette in Php con username e password usando le sessioni


Pagina 1 login.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=Entra>
<input type=reset value=Reset></form>
</body>
</html>



Pagina 2 login.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");
}
}
?>


Pagina 3 conf.php

<?
$usern= 'pippo';// username
$passw= 'pluto';// password
?>



Pagina 4 logout.php

<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) {
session_unset();
session_destroy();
echo "Hai effettuato il log out!!";
} ?>



Pagina 5 protetta.php

<?php
include 'conf.php';
session_start();
if ($_SESSION['username']==$usern) { ?>

Benvenuto nella pagina protetta<br>

<a href=logout.php>Log OUt</a>
<? } ?>



Commenti

Post popolari in questo blog

Simulazioni di reti (con Cisco Packet Tracer)

Esercizi sulla rappresentazione della virgola mobile IEEE 754 (Floating Point)