Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    problema con script registrazione utente

    Slave a tutti, avrei bisogno di un aiutino.
    Ho scaricato nella sezione script php un form per effettuare la registrazione di utenti in una rea privata. Funziona tutto perfettamente però ho un problema quando in fase di registrazione sbaglio l'inserimento di dati. In pratica anche se sbaglio le password, o la mail nn è valida si registra lo stesso il nuovo utente, ma non dovrebbe essere così. Può qualcuno dare un occhiata a questo codice, magari è una sciocchezza che nn riesco a trovare

    "



    <?php
    session_start(); // Maintain session state
    header("Cache-control: private"); // Fixes IE6's back button problem.

    // Dont allow members to go to add user page
    if(@$_SESSION['user']) header("location: login.php");
    elseif(@$_POST['user']){
    // Get and set vars (without html characters)
    $user = htmlspecialchars(strtolower($_POST["user"]));
    $pass = htmlspecialchars($_POST["pass"]);
    $permission = 0; // Default: user, until admin changes
    $email = htmlspecialchars($_POST["email"]);
    $url = htmlspecialchars($_POST["url"]);

    // Add dots to date
    if($_POST["day"]) $dob = $_POST["day"]. ".". $_POST["month"]. ".". $_POST["year"];
    else $dob = false;

    $location = htmlspecialchars($_POST["location"]);
    $joined = $_POST["joined"];

    // Create the string to append
    $string = "\r\n". $user. "<del>". md5($pass). "<del>". $permission. "<del>". $email. "<del>". $url. "<del>". $dob. "<del>". $location. "<del>". $joined;

    // Make sure username doesn't already exist
    //-----------------------------------------
    // Include the flat-file
    $file = file("users.php") or die("Problem getting the user details flat-file [users.php]");

    // Get the size of file
    $totalLines = sizeof($file);

    // Get the users details line by line
    $line = 0;
    $match = 0;
    do{
    // Check the line isn't a comment
    if("//" != substr($file[$line], 0, 2)){
    // Break our records up
    @list($username, $password, $permission, $email, $url, $dob, $location, $joined) = explode("<del>", $file[$line]);

    // Check the username and passwords match
    if((strtolower($user) == strtolower($username))) $match = 1;
    else $match = 0;
    }

    // Exit loop if match found
    if($match) break;

    // Increment line count
    $line++;
    } while($line < $totalLines);

    // Only add new user if a match is not found
    if($match){
    ?>



    <script language = "javascript" type = "text/javascript">
    <!-- // Go back
    alert("Username already taken, taking you back to choose another");
    history.go(-1);
    -->
    </script>




    <?php
    }
    else{
    // Open the users file
    $fp = fopen("users.php", "a+");

    // Append the new user to end of users file
    fwrite($fp, $string);

    // Close the file
    fclose($fp);

    // Redirect to index
    header("location: index.php?new=1");
    }
    }
    else{
    ?>
    <html>
    <head>

    <link rel = "stylesheet" type = "text/css" href = "style.css">
    <title>xxxxx</title>
    <style type="text/css">
    <!--

    body {
    background-color: #000;
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    background:url(../imma/sito/sfondo.jpg) top center #000000;
    background-repeat: no-repeat;
    background-image: url(../imma/basi_sfondi/base_img.jpg);
    }





    -->
    </style>

    </head>
    <body onload = "document.getElementById('user').focus();">
    <form method = "post" action = "<?php print($_SERVER['PHP_SELF']); ?>">




    <div align="center">












    <table width="900" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td height="80"></td>
    </tr>
    <tr>
    <td class="txt_menu"><table width="870" border="0" align="center" cellpadding="0" cellspacing="0" class="txt_piccolo">
    <tr>
    <td width="50%"><span class="txt_title">Area Priv&eacute;</span></td>
    <td align="center" valign="middle"></td>
    </tr>
    <tr>
    <td width="50%"><table border = "0" cellspacing = "0" cellpadding = "10" width = "100%" align = "center" style = "height: 100%;">
    <tr>
    <td colspan = "3" valign = "bottom"></td>
    </tr>
    <tr>
    <td height = "5%" colspan = "3" valign="top"><a href = "index.php">Effettua il login </a> </td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom"><span class = "txt_body">Username</span> </td>
    <td width = "315" height = "10" valign = "bottom"><input name = "user" type = "text" class = "text" id = "user" style = "width: 80%" tabindex = "1" value="Inserisci il tuo Username">
    </td>
    <td rowspan = "7" width = "1" height = "16" align = "right" valign = "bottom"></td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom"><span class = "txt_body">Password</span> </td>
    <td width = "315" height = "10" valign = "bottom"><input type = "password" id = "pass" name = "pass" style = "width: 80%" class = "text" tabindex = "2">
    </td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom"><span class = "txt_body"> Conferma password</span> </td>
    <td width = "315" height = "10" valign = "bottom"><input type = "password" id = "pass2" name = "pass2" style = "width: 80%" class = "text" tabindex = "3">
    </td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom" class="txt_body"> email</td>
    <td width = "315" height = "10" valign = "bottom"><input type = "text" id = "email" name = "email" style = "width: 80%" class = "text" tabindex = "4">
    </td>
    </tr>

    <tr>
    <td width = "59" height = "10" valign = "bottom" class="txt_body"> Data di nascita </td>
    <td width = "315" height = "10" valign = "bottom"><span class = "txt_body">d: </span>
    <input type = "text" id = "day" name = "day" size = "2" class = "text" maxlength = "2" tabindex = "6">
    <span class = "txt_body">m: </span>
    <input type = "text" id = "month" name = "month" size = "2" class = "text" maxlength = "2" tabindex = "7">
    <span class = "txt_body">y: </span>
    <input type = "text" id = "year" name = "year" size = "4" class = "text" maxlength = "4" tabindex = "8">
    </td>
    </tr>

    <tr>
    <td height = "10" colspan="2" valign = "bottom">

    <input type = "hidden" name = "joined" value = "<?php print(date("d.m.Y H:i:s", mktime())); ?>">
    <input type = "Image" src = "next.gif" width = "75" height = "25" name = "submit" alt = "arrow pointing right: next" border = "0" align = "top" onfocus = "return checkFields();" tabindex = "10">
    </a></td></tr>
    <tr>
    <td colspan = "3" valign = "top"></td>
    </tr>
    </table></td>
    <td align="center" valign="top">









    [img]../imma/foto/locale/03.jpg[/img]</td>
    </tr>
    </table></td>
    </tr>
    </table>


    </div>
    </form>
    <script language = "javascript" type = "text/javascript">
    <!--// Check field values are correct before submitting
    function checkFields(){
    var flag = 1; // Return flag

    // Check for empty values in important fields first
    if(!document.getElementById("user").value || !document.getElementById("pass").value || !document.getElementById("pass2").value){
    alert("ERRORE: Inserisci i dati correttamente \n\nUSERNAME\nPASSWORD\nCONFIRM PASSWORD");
    document.getElementById("user").focus();
    return true;
    }
    // Check that passwords are the same

    else if(document.getElementById("pass").value != document.getElementById("pass2").value){
    alert("ERRORE: le password non corrispondono");
    document.getElementById("pass").value = '';
    document.getElementById("pass2").value = '';
    document.getElementById("pass").focus();
    return true;
    }
    // Check the day / month / year fields if there's a value in one of them
    else if(document.getElementById("day").value || document.getElementById("month").value || document.getElementById("year").value){

    // Check day first
    if((isNaN(document.getElementById("day").value)) || (document.getElementById("day").value > 31) || (document.getElementById("day").value < 1)){
    alert("ERRORE: Inserisci una data valida");
    document.getElementById("day").value = '';
    document.getElementById("day").focus();
    return true;
    }
    // Check month next
    else if((isNaN(document.getElementById("month").value)) || (document.getElementById("month").value > 12) || (document.getElementById("month").value < 1)){
    alert("Please enter a valid month in the DOB field");
    document.getElementById("month").value = '';
    document.getElementById("month").focus();
    return true;
    }


    // Finally the year
    else if((isNaN(document.getElementById("year").value)) || (document.getElementById("year").value >= <?php print date("Y", mktime()); ?>) || (document.getElementById("year").value < 1)){
    alert("Please enter a valid year in the DOB field");
    document.getElementById("year").value = '';
    document.getElementById("year").focus();
    return true;
    }

    else flag = 0;
    }
    else flag = 0;

    // One final check if the others went through fine
    if(!flag){
    if(document.getElementById("email").value){
    // Finally, check the email
    if(document.getElementById("email").value.indexOf( "@") == -1 || document.getElementById("email").value.indexOf("." ) == -1){
    alert("If entering an email addy, please make sure it is valid");
    document.getElementById("email").focus();
    return true;
    }
    else return false;
    }
    else return false;
    }
    }
    -->
    </script>

    </body>
    </html>
    <?php
    }
    ?>


    "



    poi magari se possibile, ma solo se possibile, mi dite come faccio a fare anche il check dell'età in modo che chi si iscrive sia assolutamente maggiorenne???

    grazie in anticipo...

  2. #2
    ehi!!!nessuno sa aiutarmi???
    perché i codici funzionano...se sbaglio a inserire le password o metto una mail che nn è una mail me lo riconosce...mi compare la finestrella che dice che c'è un errore, però non si ferma il processo e cmq registra il nuovo utente e va alla pagina successiva...qual'è il problema???aiuto please...

  3. #3
    se posti un'ammasso di codice incomprensibile fuori dai tag PHP e/o CODE come pensi che qualcuno possa essere in grado di aiutarti?

    In genere gli utenti sono disponibili a spendere il proprio tempo nel dare una mano, ma venirgli incontro facilitandogli la comprensione è necessario altrimenti chi ti deve dare una mano dovrà spendere un sacco di tempo a capire il problema leggendo e rileggendo il codice postato
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

  4. #4
    è vero...mi sembrava un po di difficile comprensione...e ora sembrerà stupido...ma come si fa metterlo in modo più chiaro?

  5. #5
    quando inserisci un nuovo post o apri un nuovo thread, sopra la casella dove scrivi il testo è presente un riquadro con svariati bottoni, chiamati BBCODE. Tra quelli ci sta un #, che sta ad indicare il bbcode CODE, PHP, che è il BBCODE php ed evidenzia il codice con sintassi PHP, List, Quote e via dicendo.

    Devi usare il tasto PHP.

    Qui maggiori info
    http://forum.html.it/forum/misc.php?...bbcode#buttons
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

  6. #6
    ok grazie...allora così

    Codice PHP:
    <?php
    session_start
    (); // Maintain session state
    header("Cache-control: private"); // Fixes IE6's back button problem.

    // Dont allow members to go to add user page
    if(@$_SESSION['user']) header("location: login.php");
    elseif(@
    $_POST['user']){
    // Get and set vars (without html characters)
    $user htmlspecialchars(strtolower($_POST["user"]));
    $pass htmlspecialchars($_POST["pass"]);
    $permission 0// Default: user, until admin changes
    $email htmlspecialchars($_POST["email"]);
    $url htmlspecialchars($_POST["url"]);

    // Add dots to date
    if($_POST["day"]) $dob $_POST["day"]. "."$_POST["month"]. "."$_POST["year"];
    else 
    $dob false;

    $location htmlspecialchars($_POST["location"]);
    $joined $_POST["joined"];

    // Create the string to append
    $string "\r\n"$user"<del>"md5($pass). "<del>"$permission"<del>"$email"<del>"$url"<del>"$dob"<del>"$location"<del>"$joined;

    // Make sure username doesn't already exist
    //-----------------------------------------
    // Include the flat-file
    $file file("users.php") or die("Problem getting the user details flat-file [users.php]");

    // Get the size of file
    $totalLines sizeof($file);

    // Get the users details line by line
    $line 0;
    $match 0;
    do{
    // Check the line isn't a comment
    if("//" != substr($file[$line], 02)){
    // Break our records up
    @list($username$password$permission$email$url$dob$location$joined) = explode("<del>"$file[$line]);

    // Check the username and passwords match
    if((strtolower($user) == strtolower($username))) $match 1;
    else 
    $match 0;
    }

    // Exit loop if match found
    if($match) break;

    // Increment line count
    $line++;
    } while(
    $line $totalLines);

    // Only add new user if a match is not found
    if($match){
    ?>



    <script language = "javascript" type = "text/javascript">
    <!-- // Go back
    alert("Username already taken, taking you back to choose another");
    history.go(-1);
    -->
    </script>




    <?php
    }
    else{
    // Open the users file
    $fp fopen("users.php""a+");

    // Append the new user to end of users file
    fwrite($fp$string);

    // Close the file
    fclose($fp);

    // Redirect to index
    header("location: index.php?new=1");
    }
    }
    else{
    ?>
    <html>
    <head>

    <link rel = "stylesheet" type = "text/css" href = "style.css">
    <title>xxxxx</title>
    <style type="text/css">
    <!--

    body {
    background-color: #000;
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    background:url(../imma/sito/sfondo.jpg) top center #000000;
    background-repeat: no-repeat;
    background-image: url(../imma/basi_sfondi/base_img.jpg);
    }





    -->
    </style>

    </head>
    <body onload = "document.getElementById('user').focus();">
    <form method = "post" action = "<?php print($_SERVER['PHP_SELF']); ?>">




    <div align="center">












    <table width="900" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td height="80"> </td>
    </tr>
    <tr>
    <td class="txt_menu"><table width="870" border="0" align="center" cellpadding="0" cellspacing="0" class="txt_piccolo">
    <tr>
    <td width="50%"><span class="txt_title">Area Privé</span></td>
    <td align="center" valign="middle"> </td>
    </tr>
    <tr>
    <td width="50%"><table border = "0" cellspacing = "0" cellpadding = "10" width = "100%" align = "center" style = "height: 100%;">
    <tr>
    <td colspan = "3" valign = "bottom"> </td>
    </tr>
    <tr>
    <td height = "5%" colspan = "3" valign="top"><a href = "index.php">Effettua il login </a> </td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom"><span class = "txt_body">Username</span> </td>
    <td width = "315" height = "10" valign = "bottom"><input name = "user" type = "text" class = "text" id = "user" style = "width: 80%" tabindex = "1" value="Inserisci il tuo Username">
    </td>
    <td rowspan = "7" width = "1" height = "16" align = "right" valign = "bottom"> </td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom"><span class = "txt_body">Password</span> </td>
    <td width = "315" height = "10" valign = "bottom"><input type = "password" id = "pass" name = "pass" style = "width: 80%" class = "text" tabindex = "2">
    </td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom"><span class = "txt_body"> Conferma password</span> </td>
    <td width = "315" height = "10" valign = "bottom"><input type = "password" id = "pass2" name = "pass2" style = "width: 80%" class = "text" tabindex = "3">
    </td>
    </tr>
    <tr>
    <td width = "59" height = "10" valign = "bottom" class="txt_body"> email</td>
    <td width = "315" height = "10" valign = "bottom"><input type = "text" id = "email" name = "email" style = "width: 80%" class = "text" tabindex = "4">
    </td>
    </tr>

    <tr>
    <td width = "59" height = "10" valign = "bottom" class="txt_body"> Data di nascita </td>
    <td width = "315" height = "10" valign = "bottom"><span class = "txt_body">d: </span>
    <input type = "text" id = "day" name = "day" size = "2" class = "text" maxlength = "2" tabindex = "6">
    <span class = "txt_body">m: </span>
    <input type = "text" id = "month" name = "month" size = "2" class = "text" maxlength = "2" tabindex = "7">
    <span class = "txt_body">y: </span>
    <input type = "text" id = "year" name = "year" size = "4" class = "text" maxlength = "4" tabindex = "8">
    </td>
    </tr>

    <tr>
    <td height = "10" colspan="2" valign = "bottom">

    <input type = "hidden" name = "joined" value = "<?php print(date("d.m.Y H:i:s"mktime())); ?>">
    <input type = "Image" src = "next.gif" width = "75" height = "25" name = "submit" alt = "arrow pointing right: next" border = "0" align = "top" onfocus = "return checkFields();" tabindex = "10">
    </a></td></tr>
    <tr>
    <td colspan = "3" valign = "top"> </td>
    </tr>
    </table></td>
    <td align="center" valign="top">









    [img]../imma/foto/locale/03.jpg[/img]</td>
    </tr>
    </table></td>
    </tr>
    </table>


    </div>
    </form>
    <script language = "javascript" type = "text/javascript">
    <!--// Check field values are correct before submitting
    function checkFields(){
    var flag = 1; // Return flag

    // Check for empty values in important fields first
    if(!document.getElementById("user").value || !document.getElementById("pass").value || !document.getElementById("pass2").value){
    alert("ERRORE: Inserisci i dati correttamente \n\nUSERNAME\nPASSWORD\nCONFIRM PASSWORD");
    document.getElementById("user").focus();
    return true;
    }
    // Check that passwords are the same

    else if(document.getElementById("pass").value != document.getElementById("pass2").value){
    alert("ERRORE: le password non corrispondono");
    document.getElementById("pass").value = '';
    document.getElementById("pass2").value = '';
    document.getElementById("pass").focus();
    return true;
    }
    // Check the day / month / year fields if there's a value in one of them
    else if(document.getElementById("day").value || document.getElementById("month").value || document.getElementById("year").value){

    // Check day first
    if((isNaN(document.getElementById("day").value)) || (document.getElementById("day").value > 31) || (document.getElementById("day").value < 1)){
    alert("ERRORE: Inserisci una data valida");
    document.getElementById("day").value = '';
    document.getElementById("day").focus();
    return true;
    }
    // Check month next
    else if((isNaN(document.getElementById("month").value)) || (document.getElementById("month").value > 12) || (document.getElementById("month").value < 1)){
    alert("Please enter a valid month in the DOB field");
    document.getElementById("month").value = '';
    document.getElementById("month").focus();
    return true;
    }


    // Finally the year
    else if((isNaN(document.getElementById("year").value)) || (document.getElementById("year").value >= <?php print date("Y"mktime()); ?> ) || (document.getElementById("year").value < 1)){
    alert("Please enter a valid year in the DOB field");
    document.getElementById("year").value = '';
    document.getElementById("year").focus();
    return true;
    }

    else flag = 0;
    }
    else flag = 0;

    // One final check if the others went through fine
    if(!flag){
    if(document.getElementById("email").value){
    // Finally, check the email
    if(document.getElementById("email").value.indexOf("@") == -1 || document.getElementById("email").value.indexOf(".") == -1){
    alert("If entering an email addy, please make sure it is valid");
    document.getElementById("email").focus();
    return true;
    }
    else return false;
    }
    else return false;
    }
    }
    -->
    </script>

    </body>
    </html>
    <?php
    }
    ?>

  7. #7
    oddio mi sa che ho fatto un casino...cmq da quel che posso capire in pratica qui
    Codice PHP:
    // Only add new user if a match is not found
    if($match){
    ?>



    <script language = "javascript" type = "text/javascript">
    <!-- // Go back
    alert("Username already taken, taking you back to choose another");
    history.go(-1);
    -->
    </script> 
    c'è il comando di verifica che mi permette di non registrare nessun nome se il nome è già presente. Giusto? quindi in questo caso se c'è l'errore, l'errore viene riconosciuto e tutto si ferma

    invece, alla fine del documento c'è questo
    Codice PHP:
    <script language = "javascript" type = "text/javascript">
    <!--// Check field values are correct before submitting
    function checkFields(){
    var flag = 1; // Return flag

    // Check for empty values in important fields first
    if(!document.getElementById("user").value || !document.getElementById("pass").value || !document.getElementById("pass2").value){
    alert("ERRORE: Inserisci i dati correttamente \n\nUSERNAME\nPASSWORD\nCONFIRM PASSWORD");
    document.getElementById("user").focus();
    return true;
    }
    // Check that passwords are the same

    else if(document.getElementById("pass").value != document.getElementById("pass2").value){
    alert("ERRORE: le password non corrispondono");
    document.getElementById("pass").value = '';
    document.getElementById("pass2").value = '';
    document.getElementById("pass").focus();
    return true;
    }
    // Check the day / month / year fields if there's a value in one of them
    else if(document.getElementById("day").value || document.getElementById("month").value || document.getElementById("year").value){

    // Check day first
    if((isNaN(document.getElementById("day").value)) || (document.getElementById("day").value > 31) || (document.getElementById("day").value < 1)){
    alert("ERRORE: Inserisci una data valida");
    document.getElementById("day").value = '';
    document.getElementById("day").focus();
    return true;
    }
    // Check month next
    else if((isNaN(document.getElementById("month").value)) || (document.getElementById("month").value > 12) || (document.getElementById("month").value < 1)){
    alert("Please enter a valid month in the DOB field");
    document.getElementById("month").value = '';
    document.getElementById("month").focus();
    return true;
    }


    // Finally the year
    else if((isNaN(document.getElementById("year").value)) || (document.getElementById("year").value >= <?php print date("Y"mktime()); ?> ) || (document.getElementById("year").value < 1)){
    alert("Please enter a valid year in the DOB field");
    document.getElementById("year").value = '';
    document.getElementById("year").focus();
    return true;
    }

    else flag = 0;
    }
    else flag = 0;

    // One final check if the others went through fine
    if(!flag){
    if(document.getElementById("email").value){
    // Finally, check the email
    if(document.getElementById("email").value.indexOf("@") == -1 || document.getElementById("email").value.indexOf(".") == -1){
    alert("If entering an email addy, please make sure it is valid");
    document.getElementById("email").focus();
    return true;
    }
    else return false;
    }
    else return false;
    }
    }
    -->
    </script>
    che è lo script che mi verifica se ci sono errori del tipo, mail sbagliata, password non coincidenti e altro.
    però questo non ferma il processo e anche se trova l'errore registra comunque il nuovo utente.

    Quello che dovrei fare credo sia far funzionare questo pezzo di codice allo stesso modo di quello sopra. Ma come???
    una verifica di questi parametri prima di inviare il tutto???mmm...boh...


  8. #8
    ancora non è chiaro????aiutatemi please...almeno fatemi sentire che c'è qualcuno.....

  9. #9
    ok...diciamo che sto impazzendo...
    vi metto qui il link da dove ho scaricato il pacchetto con tutto il sitema.
    può qualcuno dargli un occhiata e farmi capire dov'è l'errore???

    php.html.it/script/vedi/3726/member-area/


    si chiama MEMBER AREA
    è alla seconda pagina degli script php/protezione e password

  10. #10


    nessuno nessuno nessuno???

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.