<?php
session_start();
function loginform()
{
echo"<form action=\"\" method=\"post\">
Username: <input type=\"text\" name=\"username\">
Password: <input type=\"text\" name=\"password\">
<input type=\"submit\" name=\"login\" value=\"Login\">
</form>";
}
function logoutform(){
echo"<form action=\"\" method=\"post\">
<input type=\"submit\" name=\"logout\" value=\"Logout\">
</form>";
}
function logout()
{
session_destroy();
}
function login($username, $password)
{
$pass=md5($password);
require("config.php");
mysql_select_db("aretusaw_portale");
$result=mysql_query("SELECT * FROM USER WHERE username='$username' AND password='$pass'") or die (mysql_error());
$count=mysql_num_rows($result);
if ($count==1){
$_SESSION['login']=$username;
echo("Login avvenuto");
}
else
{
echo("Login errato, controlla password e username");
}
}
if (isset($_SESSION['login']))
{
echo("Sei loggato, puoi fare il logout cliccando sotto.");
logoutform();
}
else
{
echo("Non sei loggato, fai il login");
loginform();
}
if ($_POST['login'])
{
echo("Login in corso..");
login($POST['username'], $_POST['password']);
}
elseif($_POST['logout'])
{
echo("Stai facendo il logout");
logout();
}
?>