Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: problema codice php

  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2008
    Messaggi
    23

    problema codice php

    salve a tutti sto creando una pagina php per la registrazione degli utenti ma ho dei problemi,

    sapete dirmi cosa c'è di sbagliato in questa parte di codice??

    //generate an random number for the user neede to activate there account
    $actnum = rand( 1,999999999999);
    //make sure that the activation number is positive (YES it can happen that the number is negatief.)
    if ($actnum < 0){$actnum = $actnum + ($actnum*-2)}
    //set the error variable to an empty string.
    $error = "";

  2. #2
    Utente di HTML.it L'avatar di sotoli
    Registrato dal
    Mar 2008
    Messaggi
    150
    Così a prima vista direi che manca un ; qui:

    codice:
    if ($actnum < 0){$actnum = $actnum + ($actnum*-2); }
    Non so se questo il tuo problema, però è comunque un errore.

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2008
    Messaggi
    23
    ecco un'altro problema..

    prima di tutto grazie, non mi da più quell'errore

    ma non mi arriva la mail quando faccio la registrazione!!!!

    questo è il codice:

    <?PHP
    //retrieve al the variables that had been submited by the from
    $username1 = $HTTP_POST_VARS["username"];
    $mailadres1 = $HTTP_POST_VARS["mailadres"];
    $password1 = $HTTP_POST_VARS["password"];
    $confirmpassword1 = $HTTP_POST_VARS["confirmpassword"];
    //generate an random number for the user neede to activate there account
    $actnum = rand( 1,999999999999);
    //make sure that the activation number is positive (YES it can happen that the number is negatief.)
    if ($actnum < 0){$actnum = $actnum + ($actnum*-2); }
    //set the error variable to an empty string.
    $error = "";

    //check it the fields are not empty. if they are, append the error to the error variable ($error)
    if ($username1 == ""){$error = "$error[*]No username given
    \n";}
    if ($password1 == ""){$error = "$error[*]No password given
    \n";}
    if ($mailadres1== ""){$error = "$error[*]No mailadres given
    \n";}
    //check if the passwords match. if they don't append the error to the error variable ($errir)
    if ($password1 <> $confirmpassword1) {$error = "$error[*]Passwords do not match
    \n";}

    // let the config.php file make an database connection
    include("config.php");
    //make an query which checks if the username OR the emailadres ar in the database. if they are append an error.
    $query = "Select * from signup where username='$username1' or mailadres='$mailadres1'";
    $result = mysql_query($query);
    if ($row = mysql_fetch_array($result)){
    if ($row["username"] == $username1){$error = "$error[*]Your username is already used by another member
    \n";}
    if ($row["mailadres"] == $mailadres1){$error = "$error[*]Your e-mail adres is already registrated in our database
    \n";}
    }

    //if ther error variable is still an empty string. The summission was oke and you can start proccesing the submission
    if ($error == ""){
    //first we check wat the date and time is for the signupdate field
    $datetime = date("d-m-Y G:i ");
    //then we submit al this to the database
    $query = "INSERT INTO signup (username, password, mailadres, actnum, userlevel, signupdate ,lastlogin, lastloginfail, numloginfail) VALUES ('$username1','$password1','$mailadres1','$actnum' , '1', '$datetime','0','0','0')";
    $result = mysql_query($query);
    //and we make an (e-mail)message which contains the activation numer
    //also possible is to put a link in that message like :
    //http:// your url /activate.php?username=$username1&actnum=$actnum
    //this would allow the user to direcly submit there activation without having to enter
    //al the data again in the activation form
    $message = "Activation number: $actnum";
    // mail the message to the user
    mail($mailadres1, "Sign up script user activationcode", $message, "From: Sign-up script");
    // and redirect the user to the activation page
    header("Location: activate.php");
    }
    else
    //if $error is no longer a empty stirng there must have been error in the submision.
    //here we echo an nice line which says there are a coulple of errors and we onpen an
    //unorder list (just the <ul> tag) and we prinnt the error. also we include a link back to the
    //sign-upform
    {echo "You could not be added to the database because of the following reasons<ul>
    $error[/list]Please return to <a href=\"signup.php\">signup form</a> and try again.";
    }
    ?>

  4. #4
    Non so dove tu abbia copiato questo codice, ma il PHP è molto vecchio stile e l'HTML è decomposto.
    Ad ogni modo, la query viene eseguita???

    Aggiungi questo codice alla tua query.
    Codice PHP:
    $result mysql_query($query) OR DIE(
    "Errore Numero: "mysql_errno()."

    Descrizione: "
    .mysql_error()); 
    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

  5. #5
    Utente di HTML.it
    Registrato dal
    Dec 2008
    Messaggi
    23
    ho provato il codice (senza l'ultimo cambiamento che mi avete detto) se un altro sito e funziona mentre nell'altro sito non mi arriva.

    su alervista fa mentre su ilbello non arriva la mail

    perchè???

    altervista non mi piace perche posso apportare un numero limitato di aggiunte, cambiamenti al database ogni ora mentre su il bello non ho questo limite.

    voi che mi consigliate di fare??

  6. #6
    ho provato il codice (senza l'ultimo cambiamento che mi avete detto)
    L'ultimo cambiamento è il più importante e non l'hai messo in pratica???
    Se la query salta e non ti fai stampare a video il motivo, lo script non arriverà mai alla funzione MAIL e tu pensi che sia quello il problema, quando invece è prima!

    Visto che parli di due server diversi, e di una migrazione, sei sicuro di avere impostato le giuste credenziali di accesso al DB nel secondo hoster?

    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

  7. #7
    Utente di HTML.it
    Registrato dal
    Dec 2008
    Messaggi
    23
    si i dati sono giusti per forza perche le tabelle le aggiungeva...

    kmq provo lo stesso a mettere quel codice...


    dove lo devo inserire??

  8. #8
    Utente di HTML.it
    Registrato dal
    Dec 2008
    Messaggi
    23
    salve a tutti,
    come posso criptare la password in md5 o in sha1??
    e quale mi consigliate??

  9. #9
    Originariamente inviato da ale537
    si i dati sono giusti per forza perche le tabelle le aggiungeva...
    kmq provo lo stesso a mettere quel codice...
    dove lo devo inserire??
    Esattamemte dove era prima, con la sintassi che ti ho scritto.

    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

  10. #10
    Originariamente inviato da ale537
    salve a tutti,
    come posso criptare la password in md5 o in sha1??
    e quale mi consigliate??
    Usa entrambi gli algoritmi, così l'hash creato è un po' più solido.
    Codice PHP:
    $hash SHA1(MD5($password)); 
    Leggi bene la Guida alla sicurezza in PHP: ti viene spiegato bene perché fare un doppio hashing.

    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.