Premetto che uso Dreamweaver e i codici me li mette il programma, perchè non ne sono capace. Cmq la registrazione e il login funzionano, solo che non riesco a farlo funzionare come ho scritto sopra; quindi se mi spiegate passo dopo passo cosa, dove e come vi dico grazie.
Questa è la pagina di registrazione.
codice:
<?php require_once('Connections/con1.php'); ?>
<?php
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="/registrazione3.php";
$loginUsername = $_POST['nickname'];
$LoginRS__query = "SELECT nome FROM utenti WHERE nome='" . $loginUsername . "'";
mysql_select_db($database_con1, $con1);
$LoginRS=mysql_query($LoginRS__query, $con1) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO utenti (nome, password, email) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['nickname'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['email'], "text"));
mysql_select_db($database_con1, $con1);
$Result1 = mysql_query($insertSQL, $con1) or die(mysql_error());
$insertGoTo = "/registrazione2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Registrazione</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
@import url("/style.css");
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body background="/sfondo.jpg" onLoad="MM_validateForm('nickname3','','R','email2','','RisEmail','password2','','R');return document.MM_returnValue">
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<h1 align="center" class="stile1">Modulo di registrazione</h1>
<p align="left" class="stile3">Per giocare al nostro GDR bisogna registrarsi. Sarà sufficiente inserire un nickname, una password a vostra scelta e un indirizzo di posta elettronica valido. Il nickname scelto sarà poi lo stesso del vostro personaggio, quindi sceglietelo bene.</p>
<p align="center" class="stile3">Immettere qui sotto un nickname. </p>
<p align="center" class="Stile1">
<input name="nickname" type="text" id="nickname3">
</p>
<p align="left" class="stile3">Ora devi inserire una password. La password è utile affinché il tuo personaggio non lo usi qualcun altro. Non dare la tua password a nessuno.</p>
<p align="center" class="stile3">Inserisci qui sotto una password.</p>
<p align="center" class="Stile1">
<input name="password" type="password" id="password2">
</p>
<p align="left" class="stile3">Per concludere, inserisci la tua e-mail. L'indirizzo deve essere tuo e deve essere corretto. Alla fine della registrazione verrà mandata una e-mail all'indirizzo di posta elettronica che metti. Quando la riceverai, potrai convalidare la tua registrazione; quindi leggi attentamente quello che c'è scritto.</p>
<p align="center" class="stile3">Immetti qui sotto la tua e-mail </p>
<p align="center">
<input name="email" type="text" id="email2">
</p>
<p align="center">
<input type="submit" name="Submit" value="Invia">
</p>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>
Questa è la pagina di login.
codice:
<?php require_once('Connections/con1.php'); ?>
<?php
// *** Validate request to login to this site.
session_start();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}
if (isset($_POST['nome'])) {
$loginUsername=$_POST['nome'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/login2.htm";
$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 );
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Login</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">
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<h1 align="center" class="stile1">Login</h1>
<p align="center" class="stile3">Nickname
<input name="nome" type="text" id="nome">
</p>
<p align="center" class="stile3">Password
<input name="password" type="password" id="password">
</p>
<p align="center" class="stile3">
<input type="submit" name="Submit" value="Invia">
</p>
</form>
</body>
</html>
E questa e la pagina che compare dopo aver effettuato il login.
codice:
<!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">
<h1 align="center" class="stile1">Login effettuato!</h1>
<p align="center" class="stile3">Benvenuto!</p>
<p align="center">Vedi l'equip</p>
<p align="center">Vedi le magie</p>
<p align="center">Vedi l'intro della storia</p>
<p align="center">Vedi gli utenti registrati</p>
</body>
</html>