Skip to content

Commit

Permalink
prove_del_form
Browse files Browse the repository at this point in the history
  • Loading branch information
fe-droid committed Apr 6, 2020
1 parent c6ba05b commit c581427
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
Lezione 3/3-sessione.php
95 changes: 95 additions & 0 deletions Tommaso_felici/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
//Inizializzo la sessione...
if (!isset($_SESSION)) {
session_start();
}


if( isset($_POST["name"]) ){

//echo "CODICEEEEE";

$correct_name = "tommaso";
$correct_pswd = md5("12345");
//echo "pass nel DB: $correct_pswd";


$nome = $_POST["name"];
$pswd = $_POST["pswd"];

/*
SE NOME è UGUALE A NOMECORRETTO
E PASSOWRD = PASSWORD CORRETTA
ALLORA DICI BENVENUTO
ALTRIMENTI DICI NONE...
*/
if ( ($correct_name == $nome) && ($correct_pswd == md5($pswd)) ) {
//echo "Benvenuto $nome";

$_SESSION["login"]["accesso"] = true;
$_SESSION["login"]["user"] = $nome;

//Salvo la sessione prima di un redirect
session_write_close();

//Redirect
header("location:miahome.php");
exit();
//oppure die();


} else {
echo "Accesso non corretto";

$_SESSION["login"]["accesso"] = false;
$_SESSION["login"]["user"] = "";


}



}


?><!DOCTYPE html>
<html>
<head>
<title>Esempio di form</title>
</head>
<body>


<?php include("menu.php"); ?>

<h3>Esempio di form</h3>

<!-- <form accept-charset="UTF-8" action="3-sessione.php" method="POST"> -->
<form accept-charset="UTF-8" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<fieldset>
<legend>Login:</legend>
<br />
<label for="name">Username: </label>
<input name="name" type="text" value="" /> <br />
<br />
<label for="pswd">Password: </label>
<input name="pswd" type="password" value="" /> <br />
<br />
<label for="ricordami">Ricordami:</label>
<input name="ricordami" type="checkbox" value="1" /> <br />
<br />
<button type="submit" value="Submit">Accedi</button>
</fieldset>
</form>


<?php

if($_SESSION["login"]["accesso"] == true){
echo "Ciao ".$_SESSION["login"]["user"];

}
?>

</body>
</html>
36 changes: 36 additions & 0 deletions Tommaso_felici/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

//Inizializzo la sessione...
if (!isset($_SESSION)) {
session_start();
}

//Elimina una variabile
unset($_SESSION["login"]);


/*
unset($_SESSION["login"]["accesso"]);
unset($_SESSION["login"]["user"]);
*/



?>
<!DOCTYPE html>
<html>
<head>
<title>HOME PAGE</title>
</head>
<body>

<?php include("menu.php"); ?>

<h3>USCITO</h3>

<p>Sei uscito dall'area riservata</p>



</body>
</html>
12 changes: 12 additions & 0 deletions Tommaso_felici/menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class='menu_principale'>
<ul>
<li>
<a href="login.php">LOGIN FORM</a>
<li>
<a href="miahome.php">HOME</a>
</li>
<li>
<a href="logout.php">LOGOUT</a>
</li>
</ul>
</div>
38 changes: 38 additions & 0 deletions Tommaso_felici/miahome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
//Inizializzo la sessione...
if (!isset($_SESSION)) {
session_start();
}


if($_SESSION["login"]["accesso"] != true){

echo "Pagina riservata!!";

//Interrompo esecuzione
die();

}



?>
<!DOCTYPE html>
<html>
<head>
<title>HOME PAGE</title>
</head>
<body>

<?php include("menu.php"); ?>

<h3>AREA RISERVATA</h3>

<p>Segreti segretissimi...</p>

<li>
<a href="miahome.php">HOME</a>
</li>

</body>
</html>

0 comments on commit c581427

Please sign in to comment.