<?
/* Check User Script */
session_start();  // Start Session

include 'db.php';
// Convert to simple variables
$username = $_POST['username'];
$password = $_POST['password'];

if((!$username) || (!$password)){
	echo "Inserire TUTTE le informazioni, Grazie ! <br />";
	include 'loging.php';
	exit();
}

// Convert password to md5 hash
$password = md5($password);

// check if the user info validates the db
$sql = mysql_query("SELECT * FROM amministratore WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
	while($row = mysql_fetch_array($sql)){
	foreach( $row AS $key => $val ){
		$$key = stripslashes( $val );
	}
		// Register some session variables!
		session_register('finame');
		$_SESSION['finame'] = $finame;
		session_register('laname');
		$_SESSION['laname'] = $laname;
		session_register('emailadd');
		$_SESSION['emailadd'] = $emailadd;
		
		header("Location: amministrazione.php");
		
		
		
	}
} else {
	echo "Non puoi essere autorizzato! Nome e/o password non corrispondono!<br />
	Riprova a inserire in modo corretto!<br />";
	include 'index.php';
}
?>