Visualizzazione risultati 1 fino 3 di 3

Discussione: Problemi di login

  1. #1
    Guest

    Predefinito Problemi di login

    Salve a tutti,

    Ho il seguente problema. Ho fatto un sito creato le solite pagine, iscrizione, attivautente, login, paginariservata. Ma al momento di loggarmi, non mi fa entrare e mi dice ritorna indietro e sotto compare "utente non trovato". Ora posto tutto, cos' vi rendete conto di ciò che parlo e del problema. Ah il tutto viene inviata un'email per attivare l'account.Questo lo fa, ma poi non mi fa entrare.

    Tabella utenti:

    Codice PHP:

    create table utenti
    (

    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    nome VARCHAR(30) NOT NULL,
    cognome VARCHAR(30) NOT NULL,
    username VARCHAR(30) NOT NULL,
    email VARCHAR(40) NOT NULL,
    password VARCHAR(255) NOT NULL,
    attivo ENUM('1', '0') DEFAULT '0',
    PRIMARY KEY (id)
    );
    iscrizione.php

    Codice PHP:

    <?php

    require_once("connetti.php");


    if (!isset(
    $_POST['reg'])) {
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Modulo d'iscrizone</title>

    <center> <H1>BENVENUTO NEL SITO D'ISCIRIZIONE PROVA</H1>

    <form action= '' method="POST">

    <font face="Comic Sans MS">

    Nome: <input type="text" name="nome" maxlength="30" size ="32"> <br> <br>
    Cognome: <input type="text" name="cognome" maxlength="30" size ="32"> <br> <br>
    Username: <input type="text" name="username" maxlength="30" size ="32"> <br> <br>
    Email: <input type="text" name="email" maxlength="40" size ="42"> <br> <br>
    Rip-Email: <input type="text" name="ripemail" maxlength="40" size ="42"> <br> <br>
    Password: <input type="password" name="password" maxlength="12" size ="14"> <br> <br>
    Rip-Passw: <input type="password" name="passw" maxlength="12" size ="14"> <br> <br>
    </font>
    <center>
    <input type="submit" name="reg" value="Invio iscrizione" />
    <input type="submit" name="uscita" value="Uscita" />
    </center> </form>
    </head>
    <body>


    <?php

    } else {
    $nome = mysql_real_escape_string(strtolower(trim ($_POST['nome'])));
    $cognome = mysql_real_escape_string(strtolower(trim ($_POST['cognome'])));
    $username = mysql_real_escape_string(strtolower(trim ($_POST['username'])));
    $password = mysql_real_escape_string(trim ($_POST['password']));
    $passw = mysql_real_escape_string(trim ($_POST['passw']));
    $email = mysql_real_escape_string(trim ($_POST['email']));
    $ripemail = mysql_real_escape_string(trim ($_POST['ripemail']));


    //crittografa la passowrod

    $pass = mysql_real_escape_string(md5(trim($_POST['password'])));

    // verifico la presenza dei campi obbligator

    $ok_ko ="";

    //controllo campi compilati

    if($nome ==""){$ok_ko .= "Attenzione: il campo nome deve essere compilato. <br> <br>";}
    if(
    $cognome ==""){$ok_ko .= "Attenzione: il campo cognome deve essere compilato. <br> <br>";}
    if(
    $username ==""){$ok_ko .= "Attenzione: il campo username deve essere compilato. <br> <br>";}
    if(
    $email ==""){$ok_ko .= "Attenzione: il campo email deve essere compilato. <br> <br>";}
    if(
    $password ==""){$ok_ko .= "Attenzione: il campo password deve essere compilato. <br><br>";}


    if(
    $password != $passw){$ok_ko .= "Attenzione: le due password non coincidono. <br> <br>";}

    if(
    $email != $ripemail){$ok_ko .= "Attenzione: le due email non coincidono. <br> <br>";}
    // Controllo se lo username è presente nel db

    $checkusername=mysql_query("SELECT username FROM utenti WHERE username='$username'");
    $vuota=mysql_num_rows($checkusername);
    if(
    $vuota > 0){
    echo
    "<br> <br> <h1> Attenzione: lo username: ".$username." è già presente nell'archivio. Si prega di cambiare username. Grazie !!! </h1>";
    echo
    "<meta http-equiv='Refresh' content=4; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
    exit();

    }

    //controllo scrittura corretta dell'email

    if(!filter_var($email, FILTER_VALIDATE_EMAIL)||!filter_var($ripemail,FILTER_VALIDATE_EMAIL)){

    $ok_ko .= "indirizzo email non valido<br>";
    }
    //chiude il controllo scrittura corretta dell'email


    // Controllo se esiste l'email nel db

    $checkemail=mysql_query("SELECT email FROM utenti WHERE email='$email'");
    $vuota=mysql_num_rows($checkemail);
    if(
    $vuota > 0){
    echo
    "<br> <br> <h1> Attenzione: l'email: ".$email." è già presente nell'archivio. Si prega di cambiare email. Grazie !!! </h1>";
    echo
    "<meta http-equiv='Refresh' content=4; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
    exit();

    }


    if(
    $ok_ko !=""){
    echo
    "<h1>$ok_ko</h1>";
    echo
    "<meta http-equiv='Refresh' content='3; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
    exit();
    }else{

    $query="INSERT INTO utenti(nome, cognome, username, email, password) VALUES('$nome','$cognome','$username','$email','$pass')";

    $q_i=mysql_query($query);
    var_dump($q_i);
    // Parte riguardante l'invio email

    //require_once ("/class.phpmailler.php");

    require_once 'phpmailer/class.phpmailer.php';
    //phpmailer
    $mail = new PHPMailer();
    $mail->IsSMTP(); // telling the class to use SMTP

    #Qui c'è il debug dell'smtp, se metti un commento non stampa diavolerie, ma è utile in fase di test per capire la natura di qualche errore
    //$mail->SMTPDebug = "2"; // enables SMTP debug information (for testing)
    // 1 = errors and messages
    // 2 = messages only


    //$mail->SMTPAuth = "true"; // enable SMTP authentication
    //$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
    //$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    //$mail->Port = "465"; // set the SMTP port for the GMAIL server


    $mail->Username = "@gmail.com"; // GMAIL username


    $mail->Password = ""; // GMAIL password

    $mail->SetFrom("no_replay@myserver.org");

    $mail->Subject = "Attivazione account.";


    //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    //$mail->AltBody = "Iscrizione avvenuta correttamente. "; // optional, comment out and test

    $mail->CharSet = "UTF-8"; //Content-Type" content="text/html;

    $mail->MsgHTML('Grazie di esserti iscritto. <a href="http://utenti/fabio/MegaLaboratorio/attivautente.php?email=' . $_POST['email']
    .
    '">clicca qui per attivare</a></b>'." "."per attviare l'account. Grazie.");


    $mail->AddAddress($_POST['email']);

    if(!
    $mail->Send()) {
    echo
    "Errore nell'inviare l'email: " . $mail->ErrorInfo;
    } else {
    echo
    "Messaggio inviatro correttamente!";
    }



    echo
    "<h1> <br>Utente registrato correttamente. E' stata inviata un'email di conferma per attivare l'account. Controllare l'email, prima di accedere.</h1>";

    }
    }
    ?>
    Questo è quello che riceve l'utente quaqndo s'iscrive al sito. Inviato da questa riga.

    Codice PHP:

    $mail
    ->MsgHTML('Grazie di esserti iscritto. <a href="http://utenti/fabio/MegaLaboratorio/attivautente.php?email=' . $_POST['email']
    .
    '">clicca qui per attivare</a></b>'." "."per attviare l'account. Grazie.");

  2. #2
    Guest

    Predefinito Problemi di login II parte

    attivautente.php

    Codice PHP:

    <?php

    require_once("connetti.php");

    //$email = $email;

    $email = $_GET['email'];
    echo
    "<h1> Attivazione account $email ... </h1>";

    $qry="UPDATE utenti SET attivo='1' WHERE email='".$email."';";

    if (
    mysql_query($qry)) {
    echo
    "... Account $email attivato";
    header("Refresh: 3;URL=paginaris.php");

    // header("Refresh: 3;URL=login.php");
    header("Refresh: 3;URL=login.php");
    } else {
    echo
    "Errore: account non attivato";
    }

    ?>
    login.php

    Codice PHP:

    <?php
    require_once("connetti.php");

    if (!isset(
    $_POST['log'])) {
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Loggati</title>

    <center> <H2>DIGITARE USERNAME & PASSWORD. PREMERE <a href="iscrizione.php"> QUI</a> </H2>

    <form action= '' method="POST">
    <font face="Comic Sans MS">
    Username: <input type="text" name="username" maxlength="30" size ="32"> <br> <br>
    Password: <input type="password" name="password" maxlength="12" size ="14"> <br> <br>
    </font>
    <center>
    <input type="submit" name="log" value="Loggati" />

    </center> </form>
    </head>
    </body>
    <?php
    session_start
    ();
    //Query originale

    // $query = "SELECT id,username, nome, attivo FROM utenti WHERE username='" . $_POST['username'] . "' AND password='" . md5($_POST['password']) . "' AND attivo ='1'";

    } else {

    $query = "SELECT username, attivo, password FROM utenti WHERE username='" . $_POST['username'] . "' AND password='" . md5($_POST['password']) . "' AND attivo ='1'";

    $cerco = mysql_query($query);

    if (!isset(
    $_POST['esci'])) {

    if (!
    $cerco) {
    echo
    "Errore query: <br/>$query<br/>" . mysql_error();
    mysql_error();
    } else {

    if (
    mysql_num_rows($cerco) == 0) {
    $row = mysql_fetch_assoc($cerco);
    $_SESSION['username'] = $row['username'];
    $_SESSION['password'] = $row['password'];
    $_SESSION['attivo'] = $row['attivo'];
    $_SESSION['attivo'] = 1;


    header("Refresh: 0;URL=paginaris.php");
    } else {

    echo
    "<h2> <center>";
    echo
    'Premere su <a href="java-script:history.back();">back</a> Indietro per riprovare </h2>';
    echo
    "Utente non trovato";

    header("Refresh: 10;URL=login.php");
    echo
    "</h2> </center>";
    }
    }
    }
    }

    ?>
    paginaris.php

    Codice PHP:

    <link rel="stylesheet" type="text/css" href="coloredisfondo.css">

    <?php
    require_once("connetti.php");
    session_start();
    if(isset(
    $_COOKIE["ultimoaccesso"])) {
    $valore_cookie = date("d/m/Y - H:i:s");
    setcookie ("ultimoaccesso", $valore_cookie, time() + 365 *24*3600);
    $ultimo_cookie = $_COOKIE["ultimoaccesso"];
    $me= "Il tuo ultimo accesso è stato il: $ultimo_cookie";
    } else {
    $valore_cookie = date("d/m/Y - H:i:s");
    setcookie ("ultimoaccesso", $valore_cookie, time() + 365 *24*3600);
    $me= "Non ti sei mai collegato a questa pagina";
    }

    $stringa= strtoupper($_SESSION['nome']);
    if(isset(
    $_SESSION['nome'])) {


    echo
    '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>benvenuto</title>

    <body>

    <?php

    require_once("connetti.php");

    session_start();

    $stringa= strtoupper($_SESSION['nome']);


    if (
    ifsset($_SESSION['nome'] = $nome)) {

    //if(isset($_SESSION['nome'] )) {
    echo "Ciao " . $_SESSION['nome'];


    echo
    "Accesso non consentito";

    }


    echo
    "<div class=\"messaggio\"><h1>";

    echo
    "BENVENUTO ".$stringa." <br />";
    echo
    $me;
    echo
    "</h1></div>";
    echo
    "</body></html>";
    }else{
    header("Location:failed.html");
    exit();

    }

    ?>

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>


    <center> <br> <br>


    <input type="button" onClick="window.location.href='logout.php';" style='padding:10px' value="Logout" />



    </center>
    </body>
    </html>
    Questo è quanto, e questa è la frase di quando mi loggo:


    Premere su back Indietro per riprovare
    Utente non trovato

    Mi potete dare una mano per favore ???? Sono settimane che ci sto dietro senza trovare una soluzione. Dove sbaglio ???? Grazie.

  3. #3
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,427

    Predefinito

    Occhio alle sql injection. Non hai usato per niente la mysql_real_escape_string() per i dati provenienti dal form.

    La session_start() andrebbe messa prima di qualsiasi output html.

    Prova a verificare (nel file del login) in quali branch dell'if prosegue il flusso del codice, ad esempio con degli echo.

    Infine, aggiungi prima di qualsiasi cosa error_reporting(E_ALL);, in modo di vedere anche gli eventuali avvisi utili non mostrati normalmente...

    Ciao!
    Ultima modifica di alemoppo : 16-10-2012 alle ore 23.55.39

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •