- Home
- Categorie
- Coding e Sistemistica
- PHP
- script login
-
dunque..ho risolto la parte delle sessioni, cosi' ora inserisco tutto alla fine.
fatto tutto con $_GET.questo è il codice finale nella pagina del login, ora mi rimane da mettere delle sicurezze e soprattutto la verifica che l'username non sia già presente e se presente farglielo sapere.
infine,come potrei gestire un invio automatico di email se l'utente richiede la password?
grazie davvero!<?php
session_start();
?><?/* Acquisizione Variabili Registrazione Da Register.php /
$_SESSION['username'] = $_GET['username'];
$_SESSION['password'] = $_GET['password'];
/ Impostazioni Su Variabili acquisite */
// Criptazione MD5 Password
$passwordcript = md5('$password');$connessione=mysql_connect("localhost", "");
$selezione_db=mysql_select_db("guest_book", $connessione);
$inserimento=mysql_query( "insert into messaggi (id_user,username,password,user,gender,date_of_birth,country,test_arousal_photo1,test_valence_photo1,test_arousal_photo2,test_valence_photo2,test_arousal_photo3,test_valence_photo3,test_arousal_photo4,test_valence_photo4,test_arousal_photo5,test_valence_photo5,test_arousal_photo6,test_valence_photo6,test_arousal_photo7,test_valence_photo7,test_arousal_photo8,test_valence_photo8,test_arousal_photo9,test_valence_photo9,test_arousal_photo10,test_valence_photo10,date) values ('" . $_SESSION['id_user']. "','" . $_SESSION['username']. "','" . $_SESSION['password']. "', '" . $_SESSION['user']. "','" . $_SESSION['gender'] . "','" . $_SESSION['year'] . "-" . $_SESSION['month'] . "-" . $_SESSION['day'] . "','" . $_SESSION['country'] . "','" . $_SESSION['test_arousal_photo1'] . "','" . $_SESSION['test_valence_photo1'] . "','" . $_SESSION['test_arousal_photo2'] . "','" . $_SESSION['test_valence_photo2'] . "','" . $_SESSION['test_arousal_photo3'] . "','" . $_SESSION['test_valence_photo3'] . "','" . $_SESSION['test_arousal_photo4'] . "','" . $_SESSION['test_valence_photo4'] . "','" . $_SESSION['test_arousal_photo5'] . "','" . $_SESSION['test_valence_photo5'] . "','" . $_SESSION['test_arousal_photo6'] . "','" . $_SESSION['test_valence_photo6'] . "','" . $_SESSION['test_arousal_photo7'] . "','" . $_SESSION['test_valence_photo7'] . "','" . $_SESSION['test_arousal_photo8'] . "','" . $_SESSION['test_valence_photo8'] . "','" . $_SESSION['test_arousal_photo9'] . "','" . $_SESSION['test_valence_photo9'] . "','" . $_SESSION['test_arousal_photo10'] . "','" . $_SESSION['test_valence_photo10'] . "', now())" );?>
-
Come dicevo poco fa' ....... utilizza quello che vuoi ma NON $_GET per inviare i dati.
Senno' tanto vale che lasci accesso liberoUtilizzare $_GET è come mettere una copia delle chiavi di casa sotto il tappetino di Welcome che hai all'esterno
-
ma ho utilizzao $_GET per tutte le sessioni... devo ricambiare tutto?
se utilizzo $_POST è meglio?
-
Come potrai vedere dalle FAQ di sezione utilizzare il metodo GET, se parliamo di sicurezza, è la prima cosa che devi evitare dato che i dati vengono passati IN CHIARO tramite url.
Si, il metodo POST è decisamente meglio, dato che passa i valori in background, ma occhio, ricordati di inizializzare sempre le variabili prima di usarle in uno script
[php]$username=""; // variabile inizializzata[/php]
-
grazie mille, trasformero' tutto in POst allora.
ultima cosa prima di chiudere oggi......
come posso impedire all'utente di tornare indietro nelle pagine?
-
a che io sappia non puoi impedirlo a 360°, anche se fai sparire la barra di navigazione l'utente dovrebbe comunque avere la possibilità di farlo tramite click destro.
Forse puoi prevedere un alert Js, ma ripeto, non mi è mai capitato, potrei sbagliarmi (anzi è molto probabile)
-
ho un problema con il login:
se lo faccio dal browser in cui ho messo password e username me lo ricorda con le sessioni, se pero' chiudo e riapro, sembra non riesca a trovare nel database l'utente con quei valori...index:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Skyline">
<title>Login</title>
</head>
<body>
<form action="login.php" method="post" enctype="application/x-www-form-urlencoded" name="login">
<input type="text" value="Username" size="20" maxlength="20" name="username" /><br />
<input type="password" value="Password" size="20" maxlength="20" name="password" /><br />
<input type="submit" value="Login" name="Submit" />
</form>
</body>
</html>login:
<?php
//includo il file di Configurazione con session_start()) dentro
include "config.php";
//Eseguo una query nella tabella utenti verificando se esiste l'username con quella password
$query = mysql_query("SELECT username FROM utenti WHERE username = '".$_POST['username']."' AND password = '".md5($_POST['password'])."'");
//se esegue la query entra nell'IF
if($query)
{
//metto l'username nella variabile di sessione "username"
$_SESSION['username'] = $_POST['username'];
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
else
{
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
?>config:
<?php
session_start();
$connection = mysql_connect( 'localhost', ) or die('Could not connect to server.' );
mysql_select_db('guest_book', $connection) or die('Could not select database.');
?>login:
<?php
//includo il file di Configurazione con session_start()) dentro
include "config.php";
//se esiste la variabile $_SESSION['username'] è loggato
if(isset($_SESSION['username']))
echo "Benvenuto ".$_SESSION['username']." hai effettuato il login con successo<br />Puoi effettuare il logout";
//Altrimenti non è loggato
else
echo "Non hai fatto il login correttamente, mi spiace <a href="index1.php">riprova</a> o <a href="register.php">iscriviti</a>";
?>logout:
<?php
//distruggo le sessioni per fare il logout
session_destroy();
echo "Logout effettuato";
echo "<script>
window.location = "index.php"
</script>";
?>
-
Guarda come ti ha salvato i dati nel Db per prima cosa e poi fai un echo dei valori postati dalla pagina index.
Vediamo se c'è qualcosa che non va
-
come lo richiamo l'echo da qui?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Skyline">
<title>Login</title>
</head>
<body>
<form action="login.php" method="post" enctype="application/x-www-form-urlencoded" name="login">
<input type="text" value="Username" size="20" maxlength="20" name="username" /><br />
<input type="password" value="Password" size="20" maxlength="20" name="password" /><br />
<input type="submit" value="Login" name="Submit" />
</form>
</body>
</html>
-
i dati sono stati già salvati con $_POST ma al richiamo dal login dice che non ci sono:bho:
-
da qui non seleziona la tabella del db. potrebbe essere questo?
<?php
session_start();
$connection = mysql_connect( 'localhost', ) or die('Could not connect to server.' );
mysql_select_db('guest_book', $connection) or die('Could not select database.');?>
-
ho fatto un po di modifiche è l'ho testato in locale, funge tutto
index.html
[html]<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Skyline">
<title>Login</title>
</head>
<body>
<form action="login.php" method="post" enctype="application/x-www-form-urlencoded" name="login">
<input type="text" value="username" size="20" maxlength="20" name="username"><br>
<input type="password" value="password" size="20" maxlength="20" name="password"><br>
<input type="submit" value="Login" name="Submit">
</form>
</body>
</html>[/html]login.php
[php]<?php
//includo il file di Configurazione con session_start()) dentro
include "config.php";
//Eseguo una query nella tabella utenti verificando se esiste l'username con quella password
$username="";
$psw="";
$username=$_POST['username'];
$psw=md5($_POST['password']);
$query = mysql_query("SELECT username FROM utenti WHERE username='$username' AND password='$psw'") or die (mysql_error());
$veruser = mysql_num_rows ($query);
//se esegue la query entra nell'IF
if($veruser !== 0)
{
//metto l'username nella variabile di sessione "username"
session_start();
$_SESSION['username'] = $_POST['username'];
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
else
{
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
@mysql_close($connection);
?>
[/php]config.php
[php]<?php
$connection = mysql_connect( 'localhost', 'userdb', 'pswdb') or die('Could not connect to server.' );
mysql_select_db('dbname', $connection) or die('Could not select database.');
?>[/php]enter.php
[php]<?php
//includo il file di Configurazione con session_start()) dentro
include "config.php";
//se esiste la variabile $_SESSION['username'] è loggato
session_start();
if($_SESSION['username'] != "")
{
echo "Benvenuto ".$_SESSION['username']." hai effettuato il login con successo<br>Puoi effettuare il <a href="logout.php">logout</a>.";
}
//Altrimenti non è loggato
else
{
echo "Non hai fatto il login correttamente, mi spiace <a href="index.html">riprova</a> o <a href="register.php">iscriviti</a>";
}
?>[/php]logout.php
[php]<?php
//distruggo le sessioni per fare il logout
session_start();
session_unset();
session_destroy();
echo "Logout effettuato";
echo "<script>
window.location = "index.html"
</script>";
?>[/php]register.php
[php]<html>
<head>
<title>Iscriviti</title>
</head>
<body>
<form action="register.php" method="POST" name="register">
Username<input type="text" name="username"><br>
Password<input type="password" name="password"><br>
Verifica password<input type="password" name="repassword"><br>
<input type="submit" value="Iscriviti">
<?
include "config.php";
// inizializza sempre le variabili che usi in uno script
$username="";
$psw="";
$repsw="";
// assegna i valori POSTati a queste variabili hashando la password
$username=$_POST['username'];
$psw=md5($_POST['password']);
$repsw=md5($_POST['repassword']);
$ver = "SELECT * FROM utenti WHERE username= '$username'";
$tabver = @mysql_query ($ver) or die (mysql_error());
$veruser = mysql_num_rows ($tabver);
if ($username=='' || $psw=='' || $repsw=='')
{
echo '<br>Compila correttamente tutti i campi';
}
else if ($psw !== $repsw)
{
echo "<br>Controllare la password digitata.";
}
else if ($veruser !== 0)
{
echo "<br>L'username richiesto risulta già registrato";
}
else if (eregi("[:,;èéçòà °@#ù§*+^ì'<>?!£$%&/=()]", $username))
{
echo "<br>Il nick contiene caratteri non validi.";
}
else
{
$sql = "INSERT INTO utenti (username, password) VALUES ('$username', '$psw')";
$query= @mysql_query($sql) or die (mysql_error());
echo "<br>Registrazione effettuata.";
}
@mysql_close($connection);
?>
</body>
</html>[/php]Ci andrebbero altri controlli per eliminare SQL injection pero', ma già il grosso è fatto così
-
ciao, grazie per lo script.
pero' io ho gia' una sessione attiva dato che la registrazione la devo mettere quasi alla fine di tutto, quindi mi dice:
Notice: A session had already been started - ignoring session_start() in c:\programmi\easyphp1-8\www\config.php on line 2
poi...
La tabella 'guest_book.utenti' non esiste
infatti la tabella si chiama messaggi e il db si chiama guest_book.index3:
<?php
session_start();
?><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="Skyline">
<title>Login</title>
</head>
<body>
<form action="login2.php" method="post" enctype="application/x-www-form-urlencoded" name="login">
<input type="text" value="username" size="20" maxlength="20" name="username"><br>
<input type="password" value="password" size="20" maxlength="20" name="password"><br>
<input type="submit" value="Login" name="Submit">
</form>
</body>
</html>login2:
<?php
session_start();
?>
<?php
//includo il file di Configurazione con session_start()) dentro
include "config.php";
//Eseguo una query nella tabella utenti verificando se esiste l'username con quella password
$username="";
$psw="";
$username=$_POST['username'];
$psw=md5($_POST['password']);
$query = mysql_query("SELECT username FROM utenti WHERE username='$username' AND password='$psw'") or die (mysql_error());
$veruser = mysql_num_rows ($query);
//se esegue la query entra nell'IF
if($veruser !== 0)
{
//metto l'username nella variabile di sessione "username"
session_start();
$_SESSION['username'] = $_POST['username'];
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
else
{
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
@mysql_close($connection);
?>config:
<?php
session_start();
$connection = mysql_connect( 'localhost', ) or die('Could not connect to server.' );
mysql_select_db('guest_book', $connection) or die('Could not select database.');
?>enter:
<?php
session_start();
?>
<?php
//includo il file di Configurazione con session_start()) dentro
include "config.php";
//se esiste la variabile $_SESSION['username'] è loggato
session_start();
if($_SESSION['username'] != "")
{
echo "Benvenuto ".$_SESSION['username']." hai effettuato il login con successo<br>Puoi effettuare il <a href="logout.php">logout</a>.";
}
//Altrimenti non è loggato
else
{
echo "Non hai fatto il login correttamente, mi spiace <a href="index.html">riprova</a> o <a href="register.php">iscriviti</a>";
}
?>logout:
<?php
session_start();
?>
<?php
//distruggo le sessioni per fare il logout
session_start();
session_unset();
session_destroy();
echo "Logout effettuato";
echo "<script>
window.location = "index.html"
</script>";
?>register:
<?php
session_start();
?>
<html>
<head>
<title>Iscriviti</title>
</head>
<body>
<form action="register.php" method="POST" name="register">
Username<input type="text" name="username"><br>
Password<input type="password" name="password"><br>
Verifica password<input type="password" name="repassword"><br>
<input type="submit" value="Iscriviti">
<?
include "config.php";
// inizializza sempre le variabili che usi in uno script
$username="";
$psw="";
$repsw="";
// assegna i valori POSTati a queste variabili hashando la password
$username=$_POST['username'];
$psw=md5($_POST['password']);
$repsw=md5($_POST['repassword']);
$ver = "SELECT * FROM utenti WHERE username= '$username'";
$tabver = @mysql_query ($ver) or die (mysql_error());
$veruser = mysql_num_rows ($tabver);
if ($username=='' || $psw=='' || $repsw=='')
{
echo '<br>Compila correttamente tutti i campi';
}
else if ($psw !== $repsw)
{
echo "<br>Controllare la password digitata.";
}
else if ($veruser !== 0)
{
echo "<br>L'username richiesto risulta già registrato";
}
else if (eregi("[:,;èéçòà °=()]", $username))
{
echo "<br>Il nick contiene caratteri non validi.";
}
else
{
<?$connessione=mysql_connect("localhost", "");
$selezione_db=mysql_select_db("guest_book", $connessione);$inserimento=mysql_query( "insert into messaggi (id_user,username,password,user,gender,date_of_birth,country,test_arousal_photo1,test_valence_photo1,test_arousal_photo2,test_valence_photo2,test_arousal_photo3,test_valence_photo3,test_arousal_photo4,test_valence_photo4,test_arousal_photo5,test_valence_photo5,test_arousal_photo6,test_valence_photo6,test_arousal_photo7,test_valence_photo7,test_arousal_photo8,test_valence_photo8,test_arousal_photo9,test_valence_photo9,test_arousal_photo10,test_valence_photo10,date) values ('" . $_SESSION['id_user']. "','" . $_POST['username'] . "','" . $_POST['password'] . "', '" . $_SESSION['user']. "','" . $_SESSION['gender'] . "','" . $_SESSION['year'] . "-" . $_SESSION['month'] . "-" . $_SESSION['day'] . "','" . $_SESSION['country'] . "','" . $_SESSION['test_arousal_photo1'] . "','" . $_SESSION['test_valence_photo1'] . "','" . $_SESSION['test_arousal_photo2'] . "','" . $_SESSION['test_valence_photo2'] . "','" . $_SESSION['test_arousal_photo3'] . "','" . $_SESSION['test_valence_photo3'] . "','" . $_SESSION['test_arousal_photo4'] . "','" . $_SESSION['test_valence_photo4'] . "','" . $_SESSION['test_arousal_photo5'] . "','" . $_SESSION['test_valence_photo5'] . "','" . $_SESSION['test_arousal_photo6'] . "','" . $_SESSION['test_valence_photo6'] . "','" . $_SESSION['test_arousal_photo7'] . "','" . $_SESSION['test_valence_photo7'] . "','" . $_SESSION['test_arousal_photo8'] . "','" . $_SESSION['test_valence_photo8'] . "','" . $_SESSION['test_arousal_photo9'] . "','" . $_SESSION['test_valence_photo9'] . "','" . $_SESSION['test_arousal_photo10'] . "','" . $_SESSION['test_valence_photo10'] . "', now())" );
mysql_close($connessione);
?></body>
</html>
-
dunque, rispetto a prima che mi dava l'inesistenza della taballa utenti, giustamente l'ho cambiata in messaggi:
<?php
//includo il file di Configurazione con session_start()) dentro
include "config.php";
//Eseguo una query nella tabella messaggi verificando se esiste l'username con quella password
$username="";
$psw="";
$username=$_POST['username'];
$psw=md5($_POST['password']);
$query = mysql_query("SELECT username FROM messaggi WHERE username='$username' AND password='$psw'") or die (mysql_error());
$veruser = mysql_num_rows ($query);
//se esegue la query entra nell'IF
if($veruser !== 0)
{
//metto l'username nella variabile di sessione "username"
session_start();
$_SESSION['username'] = $_POST['username'];
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
else
{
//Faccio il redirect nella pagine enter.php
echo "<script>
window.location = "enter.php"
</script>";
}
@mysql_close($connection);
?>adesso il problema è che mi visualizza questo:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\programmi\easyphp1-8\www\config.php:8) in c:\programmi\easyphp1-8\www\enter.php on line 5
Notice: Undefined index: username in c:\programmi\easyphp1-8\www\enter.php on line 6
Non hai fatto il login correttamente, mi spiace riprova o iscriviti
-
dunque, sembra che per ora sia risolto..faccio login e registrazione, ...grazie!
ora provo a mettere le tutto con le sessioni.
-
allora, ora ci siamo quasi, tutto bene, registra ecc.
pero', c'è sempre un pero', siccome ho messo tutto in una sessione che parte dall'inizio, e avendo messo nel database la chiave primaria id_autoincrement, succede che ogni volta che mi connetto al database, tipo per controllare l'utente, o magari solo per l'iscrizione, ovviamente mi incrementa di uno.
come potrei ovviare a tutto cio'?
thanksquesta è l'ultima pagina dello script che contiene tutte le variabili
<?php
session_start();
?>
<html>
<head>
<title>Iscriviti</title>
</head>
<body>
<form action="register2.php" method="POST" name="register">
Username<input type="text" name="username"><br>
Password<input type="password" name="password"><br>
Verifica password<input type="password" name="repassword"><br>
<input type="submit" value="Iscriviti">
<?
include "config.php";
// inizializza sempre le variabili che usi in uno script
$username="";
$psw="";
$repsw="";
// assegna i valori POSTati a queste variabili hashando la password
$username=$_POST['username'];
$psw=md5($_POST['password']);
$repsw=md5($_POST['repassword']);
$ver = "SELECT * FROM messaggi WHERE username= '$username'";
$tabver = @mysql_query ($ver) or die (mysql_error());
$veruser = mysql_num_rows ($tabver);
if ($username=='' || $psw=='' || $repsw=='')
{
echo '<br>Compila correttamente tutti i campi';
}
else if ($psw !== $repsw)
{
echo "<br>Controllare la password digitata.";
}
else if ($veruser !== 0)
{
echo "<br>L'username richiesto risulta già registrato";
}
else if (eregi("[:,;èéçòà =()]", $username))
{
echo "<br>Il nick contiene caratteri non validi.";
}
else
{
$sql = "INSERT INTO messaggi (username, password) VALUES ('$username', '$psw')";$inserimento=mysql_query( "insert into messaggi (id_user,username,password,user,gender,date_of_birth,country,test_arousal_photo1,test_valence_photo1,test_arousal_photo2,test_valence_photo2,test_arousal_photo3,test_valence_photo3,test_arousal_photo4,test_valence_photo4,test_arousal_photo5,test_valence_photo5,test_arousal_photo6,test_valence_photo6,test_arousal_photo7,test_valence_photo7,test_arousal_photo8,test_valence_photo8,test_arousal_photo9,test_valence_photo9,test_arousal_photo10,test_valence_photo10,date) values ('" . $_SESSION['id_user']. "','" . $_POST['username']. "','" . $_POST['password']. "', '" . $_SESSION['user']. "','" . $_SESSION['gender'] . "','" . $_SESSION['year'] . "-" . $_SESSION['month'] . "-" . $_SESSION['day'] . "','" . $_SESSION['country'] . "','" . $_SESSION['test_arousal_photo1'] . "','" . $_SESSION['test_valence_photo1'] . "','" . $_SESSION['test_arousal_photo2'] . "','" . $_SESSION['test_valence_photo2'] . "','" . $_SESSION['test_arousal_photo3'] . "','" . $_SESSION['test_valence_photo3'] . "','" . $_SESSION['test_arousal_photo4'] . "','" . $_SESSION['test_valence_photo4'] . "','" . $_SESSION['test_arousal_photo5'] . "','" . $_SESSION['test_valence_photo5'] . "','" . $_SESSION['test_arousal_photo6'] . "','" . $_SESSION['test_valence_photo6'] . "','" . $_SESSION['test_arousal_photo7'] . "','" . $_SESSION['test_valence_photo7'] . "','" . $_SESSION['test_arousal_photo8'] . "','" . $_SESSION['test_valence_photo8'] . "','" . $_SESSION['test_arousal_photo9'] . "','" . $_SESSION['test_valence_photo9'] . "','" . $_SESSION['test_arousal_photo10'] . "','" . $_SESSION['test_valence_photo10'] . "', now())" );
$query= @mysql_query($sql) or die (mysql_error());
echo "<br>Registrazione effettuata.";
}
@mysql_close($connection);
?>
</body>
</html>
-
non ho capito che intendi :():
-
ogni volta che mi connetto al database, tipo per controllare se l'utente esiste nel database mi incrementa di un valore nel campo id_user che è la mia chiave primaria nel db.
ora, siccome tutto è fatto con le sessioni che cominciano dall'inizio del test registrando valori e dati personali di quell'utente che puo' anche non essersi loggato, ma rimane univoco in quanto la sessione gli registra tutte le sue scelte fino alla pagina finale in cui vengono registrati i valori e i dati dell'utente 1 nel db.
se poi questo utente 1(valore nel campo id_user autoincrement nel db), volesse anche registrarsi al sito, per accedere a dei download o vedere altre pagine alle quali normalmente chi nn si registra nn puo' accedere, nel mmomento della registrazione, dopo aver inserito i dati e fatto il controllo che nn esista nessun altro col suo username, automaticamente diventa utente numero 2 in quanto è avvenuta la connessione al database per controllare username e password.
quindi la connessione sembra sia obbligatoriamente necessaria almeno 2 volte:
1 per controllare username e password
2 per inserirli
quindi, cosi' facendo mi incrementa sempre di uno il valore.
io vorrei che questo non accadesse porcapupazza, ma nn riesco a capire come.Spero di essere stato un po' piu' chiaro.hai qualche suggerimento?
grazie
-
il fatto strano, forse, è che l'utente deve effettuare tutto il test per potersi registrare, loggarsi all'inizio quando ha effettuato il test almeno 1 volta,registrarsi dunque solo verso la fine di tutto,(terzultima pagina, prima delle statistiche finali dei risultati al test) non all'inizio come nei "normali siti" .
grazie per la pazienza
-
Allora, ripetiamo che mi sono un po perso:
arrivo io che voglio fare il test e do' le mie risposte man mano alle varie pagine.
Già dalla prima pagina mi viene assegnato un SID che mi trasporto dietro nelle varie pagine e a cui viene associata la risposta pagina per pagina man mano che vado avanti nel test.
Arrivato alla fine del test:- o mi loggo (se sono già registrato) e quindi a login effettuato procedo alla prossima pagina enter.php
- oppure mi registro. E a registrazione effettuata mi loggo e arrivo nuovamente alla pagina enter.php
a questo punto possiamo immettere i dati relativi alle risposte dentro al Db, essendo io già registrato NON devo fare un nuovo INSERT INTO, ma un UPDATE (dimenticavo, nel Db metti l'username come chiave univoca
quindi nella pagina enter.php metterai:
[php]<?php
//includo il file di Configurazione
include "config.php";
//se esiste la variabile $_SESSION['username'] è loggato
session_start();
if($_SESSION['username'] != "")
{
$sql="UPDATE messaggi SET campo10='".$_SESSION['risposta1']."', campo11=etc etc etc WHERE username='".$_SESSION['username']."'";
$query=@mysql_query($sql) or die (mysql_error());
echo "Benvenuto ".$_SESSION['username']." hai effettuato il login con successo<br>Puoi effettuare il <a href="logout.php">logout</a>.";
}
//Altrimenti non è loggato
else
{
echo "Non hai fatto il login correttamente, mi spiace <a href="index.html">riprova</a> o <a href="register.php">iscriviti</a>";
}
?> [/php]
Quindi, riepilogando:
All'atto della registrazione utilizzo l'INSERT INTO per registrare nome utente, password, compleanno e tutto cio' che non c'entra con il test, l'inserimento dei dati del test invece lo faro' solo dopo, a log effettuato, utilizzando l'UPDATE del record che riguarda l'utente loggatoFacci sapere se così risolvi