Certo! Per evitare problemi ti posto tutto. Questa è la pagina di login.
Codice:
<?php require_once('Connections/con1.php'); ?><?php
// *** Validate request to login to this site.
session_start();
$_SESSION['id'] = id_dell_utente_loggato;
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}
if (isset($_POST['nickname'])) {
$loginUsername=$_POST['nickname'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/kkkk.php";
$MM_redirectLoginFailed = "/login3.htm";
$MM_redirecttoReferrer = false;
mysql_select_db($database_con1, $con1);
$LoginRS__query=sprintf("SELECT nome, password FROM utenti WHERE nome='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $con1) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;
//register the session variables
session_register("MM_Username");
session_register("MM_UserGroup");
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<html>
<head>
<title>Login</title>
<style type="text/css">
<!--
@import url("/style.css");
-->
</style>
</head>
<body background="/sfondo.jpg">
<form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" onSubmit="MM_validateForm('nickname2','','R','password2','','R');return document.MM_returnValue">
<h2 align="center" class="stile1">Login</h2>
<p align="center" class="stile3">Nickname
<input name="nickname" type="text" id="nickname2">
</p>
<p align="center" class="stile3">Password
<input name="password" type="password" id="password2">
</p>
<p align="center" class="Stile1">
<input name="Submit1" type="submit" onClick="MM_validateForm('nickname2','','R','password2','','R');return document.MM_returnValue" value="Invia">
</p>
</form>
</body>
</html>
E questa è la pagina che appare quando il login è eseguito. Volgio che a fianco di 'Benvenuto' ci sia il nickname di chi si è loggiato.
Codice:
<?php require_once('Connections/con1.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "/index.htm";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
mysql_select_db($database_con1, $con1);
$query_Recordset1 = "SELECT * FROM utenti ";
$Recordset1 = mysql_query($query_Recordset1, $con1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login effettuato!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
@import url("/style.css");
-->
</style>
</head>
<body background="/sfondo.jpg">
<div align="center">
<form name="form1" method="get" action="">
<h2 class="stile1">Ti sei loggiato correttamente al sito.</h2>
<h3 class="stile3">Benvenuto <?php echo $sql = mysql_query("SELECT * FROM utenti WHERE id = {$_SESSION['id']};");
while ($element = mysql_fetch_array($sql))
{
stampa i vari risultati...
}
?>!</h3>
<p><a href="/storia.php" class="stile2">Vedi l'intro della storia</a></p>
<p><a href="/equip.php" class="stile2">Vedi l'equip</a></p>
<p><a href="/utenti.php" class="stile2">Vedi gli utenti registrati</a></p>
</form>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>