Visualizzazione risultati 1 fino 7 di 7

Discussione: Problemi PHP - Conferma e-mail/Recupero pass

  1. #1
    L'avatar di forfree
    forfree non è connesso Neofita
    Data registrazione
    27-03-2018
    Residenza
    Trento
    Messaggi
    7

    Exclamation Problemi PHP - Conferma e-mail/Recupero pass

    Buongiorno, ho creato il sito: http://forfree.altervista.org seguendo questa guida. Il sito è praticamente un sistema di registrazione e log in, il quale invia un'email di conferma per verificare l'utente e c'è la possibilità di reimpostare la password casomai fosse stata dimenticata. Ovviamente il tutto è basto sulla correlazione tra PHP ed il DBMS MySql fornito da Altervista nel quale ho creato una tabella "utente" con i relativi attributi necessari.
    Il problema sorge quando si preme sul link di attivazione, perché inizialmente dopo aver completato i campi nome, cognome, email e password per poi premere sul pulsante di registrazione si viene reindirizzati alla pagina del profilo dove viene detto all'utente che deve verificare il suo account con il link inviato alla sua e-mail. Successivamente verificando l'email viene inviato un link del tipo: forfreee.altervista.org/verify.php?email='.$email.'&hash='.$hash.
    Questo è uno spezzone del codice all'interno del file "verify.php" che viene eseguito solamente con il link di attivazione (di cui ho esposto la struttura nella riga sopra) inviato all'email:
    Codice PHP:
    if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash'])) {
    $email = $mysqli->escape_string($_GET['email']);
    $hash = $mysqli->escape_string($_GET['hash']);

    // Select user with matching email and hash, who hasn't verified their account yet (active = 0)
    $result = $mysqli->query("SELECT * FROM users WHERE email='$email' AND hash='$hash' AND active='0'");

    if (
    $result->num_rows == 0 ) {
    $_SESSION['message'] = "Account has already been activated or the URL is invalid!";
    header("location: error.php");
    } else {
    $_SESSION['message'] = "Your account has been activated!";
    // Set the user status to active (active = 1)
    $mysqli->query("UPDATE users SET active='1' WHERE email='$email'") or die($mysqli->error);
    $_SESSION['active'] = 1;
    header("location: success.php");
    }
    } else {
    $_SESSION['message'] = "Invalid parameters provided for account verification!";
    header("location: error.php");
    }
    Casomai vi sia bisogno di altro codice del progetto per trovare l'errore è possibile trovare tutto quanto su questo link visto che il tutto è open source e come ho detto all'inizio parte di una guida online.


    MODIFICA SUCCESSIVA:
    Ovviamente se il problema avviene quando ci si registra e si cerca di fare la verifica dell'account perché non funziona il link vale lo stesso anche per il link che si riceve quando si fa la procedura per la password dimenticata.
    Ultima modifica di forfree : 30-03-2018 alle ore 16.08.32

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

    Predefinito

    Quindi quale è il problema?

    Ciao!

  3. #3
    L'avatar di forfree
    forfree non è connesso Neofita
    Data registrazione
    27-03-2018
    Residenza
    Trento
    Messaggi
    7

    Predefinito

    Il problema è che dopo aver cliccato sul link dell'email mi mostra la scritta "Impossibile raggiungere il sito" e "Impossibile trovare l'indirizzo IP del server di forfreee.altervista.org". Non capisco come fare a risolvere questo problema perché in teoria dovrei ritrovarmi sulla pagine "verify.php" e mostrarmi il messaggio che la verifica dell'account è stata effettuata correttamente.

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

    Predefinito

    Evidentemente è sbagliato il link nell'email, ti porta ad un altro sito.
    Mostra il codice che genera l'email.

    Ciao!

  5. #5
    L'avatar di forfree
    forfree non è connesso Neofita
    Data registrazione
    27-03-2018
    Residenza
    Trento
    Messaggi
    7

    Predefinito

    Ecco il codice del file "register.php" eseguito appena viene premuto il bottone di registrazione.
    Codice PHP:
    <?php
    /* Registration process, inserts user info into the database
    and sends account confirmation email message
    */

    // Set session variables to be used on profile.php page
    $_SESSION['email'] = $_POST['email'];
    $_SESSION['first_name'] = $_POST['firstname'];
    $_SESSION['last_name'] = $_POST['lastname'];

    // Escape all $_POST variables to protect against SQL injections
    $first_name = $mysqli->escape_string($_POST['firstname']);
    $last_name = $mysqli->escape_string($_POST['lastname']);
    $email = $mysqli->escape_string($_POST['email']);
    $password = $mysqli->escape_string(password_hash($_POST['password'], PASSWORD_BCRYPT));
    $hash = $mysqli->escape_string( md5( rand(0,1000) ) );

    // Check if user with that email already exists
    $result = $mysqli->query("SELECT * FROM users WHERE email='$email'") or die($mysqli->error());

    // We know user email exists if the rows returned are more than 0
    if ( $result->num_rows > 0 ) {

    $_SESSION['message'] = 'User with this email already exists!';
    header("location: error.php");

    }
    else {
    // Email doesn't already exist in a database, proceed...

    // active is 0 by DEFAULT (no need to include it here)
    $sql = "INSERT INTO users (first_name, last_name, email, password, hash) "
    . "VALUES ('$first_name','$last_name','$email','$password', '$hash')";

    // Add user to the database
    if ( $mysqli->query($sql) ){

    $_SESSION['active'] = 0; //0 until user activates their account with verify.php
    $_SESSION['logged_in'] = true; // So we know the user has logged in
    $_SESSION['message'] =

    "Confirmation link has been sent to $email, please verify
    your account by clicking on the link in the message!"
    ;

    // Send registration confirmation link (verify.php)
    $to = $email;
    $subject = 'Account Verification';
    $message_body = '
    Hello '
    .$first_name.',

    Thank you for signing up!

    Please click this link to activate your account:

    forfreee.altervista.org/verify.php?email='
    .$email.'&hash='.$hash;

    mail( $to, $subject, $message_body );

    header("location: profile.php");

    }

    else {
    $_SESSION['message'] = 'Registration failed!';
    header("location: error.php");
    }

    }
    Ultima modifica di forfree : 30-03-2018 alle ore 16.27.22

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

    Predefinito

    Hai messo 3 "e" in forfreee.

    Ciao!

  7. #7
    L'avatar di forfree
    forfree non è connesso Neofita
    Data registrazione
    27-03-2018
    Residenza
    Trento
    Messaggi
    7

    Predefinito

    Hai ragione, che errore stupido.
    Grazie

Tags for this Thread

Regole di scrittura

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