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

Discussione: codice login

  1. #1

    codice login

    Libreria di connessionen: dbconn.php
    <?php
    $_CONFIG['host'] = "localhost";
    $_CONFIG['user'] = "root";
    $_CONFIG['pass'] = "root";
    $_CONFIG['dbname'] = "accessi";

    $_CONFIG['table_sessioni'] = "sessioni";
    $_CONFIG['table_utenti'] = "utenti";

    $_CONFIG['expire'] = 60;
    $_CONFIG['check_table'] = array(
    "username" => "check_username",
    "password" => "check_global",
    "name" => "check_global",
    "surname" => "check_global",
    "indirizzo" => "check_global",
    "occupazione" => "check_global",
    "mail" => "check_global"
    );

    function check_username($value){
    global $_CONFIG;
    $value = trim($value);
    if($value == "")
    return "Il campo non può essere lasciato vuoto";
    $query1 = "SELECT id FROM utenti
    WHERE username='".$value."';";
    $result= connessione($sql);
    $count=mysql_num_rows($result);
    if(mysql_num_rows($count) != 0)
    return "Nome utente già utilizzato";
    return true;
    }

    function check_global($value){
    global $_CONFIG;
    echo "check .$value".;
    $value = trim($value);
    if($value == "")
    return "Il campo non può essere lasciato vuoto";

    return true;
    }


    function connessione($sql)
    {
    $dbuser="root";
    $dbpass="root";
    $dbname="accessi";
    $dbhost="localhost";
    $connessione=mysql_connect($dbhost,$dbuser,$dbpass ) or die("Connessione non riuscita: " . mysql_error());
    mysql_select_db($dbname) or die("Selezione del database non riuscita");
    $rs=mysql_query($sql) or die ("errore query");
    mysql_close($connessione);
    return $rs;


    }

    function closeconnessione($result)
    {
    mysql_free_result($result);
    }

    ?>

    Libreria di registrazione:
    reg.lib.php
    <?php
    include_once 'include/dbconn.php';

    function reg_register($data){
    //registro l'utente
    global $_CONFIG;

    $id = reg_get_unique_id();
    $query= "INSERT INTO utenti (name, surname, username, password, temp, regdate, uid) VALUE ('".$data['name']."','
    ".$data['surname']."','".$data['username']."',MD5('".$data['password']."','1', '".time()."','".$id."');";
    echo " 1 chiamata";
    connessione($query);
    //Decommentate la riga seguente per testare lo script in locale
    //echo "<a href=\"http://localhost/Articoli/autenticazione/2/scripts/confirm.php?id=".$id."\">Conferma</a>";
    if(mysql_insert_id()){
    return reg_send_confirmation_mail($data['mail'], "test@localhost", $id);
    }else return REG_FAILED;
    }

    function reg_send_confirmation_mail($to, $from, $id){
    //invio la mail di conferma
    $msg = "Per confermare l'avvenuta registrazione, clicckate il link seguente:
    http://localhost/Articoli/autenticaz...onfirm.php?id=".$id."
    ";
    return (mail($to, "Conferma la registrazione", $msg, "From: ".$from)) ? REG_SUCCESS : REG_FAILED;
    }

    function reg_clean_expired(){
    global $_CONFIG;

    $query1 ="DELETE FROM ".$_CONFIG['table_utenti']."WHERE (regdate + ".($_CONFIG['regexpire'] * 60 * 60).") <= ".time()."
    and temp='1'";
    echo " 2 chiamata";
    connessione($query1);
    }

    function reg_get_unique_id(){
    //restituisce un ID univoco per gestire la registrazione
    list($usec, $sec) = explode(' ', microtime());
    mt_srand((float) $sec + ((float) $usec * 100000));
    return md5(uniqid(mt_rand(), true));
    }

    function reg_check_data(&$data){
    global $_CONFIG;

    $errors = array();

    foreach($data as $field_name => $value){
    $func = $_CONFIG['check_table'][$field_name];
    connessione($func);
    if(!is_null($func)){
    $ret = $func($value);
    if($ret !== true)
    $errors[] = array($field_name, $ret);
    }
    }

    return count($errors) > 0 ? $errors : true;
    }

    function reg_confirm($id){
    global $_CONFIG;

    $query2 ="UPDATE ".$_CONFIG['table_utenti']."
    SET temp='0'
    WHERE uid='".$id."'";
    echo " 2 chiamata";
    connessione($query2);
    return (mysql_affected_rows () != 0) ? REG_SUCCESS : REG_FAILED;
    }
    ?>

    register.php

    <html>
    <head>
    <style type="text/css">
    <!--
    .style1 {
    color: #FF0000;
    font-weight: bold;
    }
    -->
    </style>
    </head>
    <body>
    <?php
    include_once("include/dbconn.php");
    include_once("include/reg.lib.php");

    if(isset($_POST['action']) and $_POST['action'] == 'Invia'){
    $ret = reg_check_data($_POST);
    $status = ($ret === true) ? reg_register($_POST) : REG_ERRORS;

    switch($status){
    case REG_ERRORS:
    ?>
    <span class="style1">Sono stati rilevati i seguenti errori:</span>

    <?php
    foreach($ret as $error)
    printf("%s: %s
    ", $error[0], $error[1]);
    ?>

    Premere "indietro" per modificare i dati
    <?php
    break;
    case REG_FAILED:
    echo "Registrazione Fallita a causa di un errore interno.";
    break;
    case REG_SUCCESS:
    echo "Registrazione avvenuta con successo.

    Vi è stata inviata una email contente le istruzioni per confermare la registrazione.";
    break;
    }
    }
    ?>
    </body>
    </html>
    verificalog.php
    <?php
    include_once 'include/dbconn.php';

    $username=$_POST['uname'];
    $password=$_POST['passw'];
    echo "username: ".$username."
    ";
    echo "password: ".$password."
    ";
    //$sql="SELECT * FROM utenti WHERE username='".$username."' and password='".$password."
    ";;
    $sql="SELECT * FROM utenti WHERE username='".$username."' and password='".$password."';";
    $result= connessione($sql);
    $count=mysql_num_rows($result);
    if ($count==0){
    echo "ritenta";}
    else{
    echo "benvenuto";}

    ?>

  2. #2
    e quale sarebbe il problema?

  3. #3
    da problemi la funzione
    function check_username($value){
    global $_CONFIG;
    $value = trim($value);
    if($value == "")
    return "Il campo non può essere lasciato vuoto";
    $query1 = "SELECT id FROM utenti
    WHERE username='".$value."';";
    $result= connessione($sql);
    $count=mysql_num_rows($result);
    if(mysql_num_rows($count) != 0)
    return "Nome utente già utilizzato";
    return true;
    }
    da errore di query

  4. #4
    Innanzitutto:

    $query1 = "SELECT id FROM utenti WHERE username='".$value."';";

    nella query non devi mettere il ;


    $query1 = "SELECT id FROM utenti WHERE username='".$value."'";

    Poi un consiglio:

    non iniziare i nomi di variabili con l'_ è meglio evitare perché in genere vengono usati per variabili predefinite e quindi inavvertitamente potresti usare il nome di una variabile che tu credi di aver definito ma che in realtà esiste già!

    poi questa istruzione
    global $_CONFIG;

    non serve visto che nella funzione non usi la variabile $_CONFIG

  5. #5
    Qui invece:

    $result= connessione($sql);

    forse dovresti scrivere

    $result= connessione($query1);
    anche perché $sql non l'hai definita

  6. #6
    Un'altra osservazione su:

    function check_username($value)
    {
    global $_CONFIG;
    $value = trim($value);
    if ($value == "") return "Il campo non può essere lasciato vuoto";
    $query1 = "SELECT id FROM utenti WHERE username='".$value."';";
    $result= connessione($sql);
    $count=mysql_num_rows($result);
    if (mysql_num_rows($count) != 0)
    return "Nome utente già utilizzato";
    return true;
    }


    Quando fai:

    $result= connessione($sql);

    in connessione apri la connessione al DB, esegui la query mettendo il risultato nella var.le $rs che poi ritorni e chiudi la connessione al DB:

    $rs=mysql_query($sql) or die ("errore query");
    mysql_close($connessione);
    return $rs;


    Quando poi riprendi con check_username

    mysql_num_rows($count);

    a questo punto però il DB lo hai chiuso quindi onestamente non so se questa istruzione venga eseguita correttamente

  7. #7
    cmq mi da lo stessso errore un modo per aggiustarlo?

  8. #8
    puoi postare il nuovo codice modificato?

  9. #9
    puoi anche dire qual è l'errore preciso che ti da?

  10. #10
    <?php
    $_CONFIG['host'] = "localhost";
    $_CONFIG['user'] = "root";
    $_CONFIG['pass'] = "root";
    $_CONFIG['dbname'] = "accessi";

    $_CONFIG['table_sessioni'] = "sessioni";
    $_CONFIG['table_utenti'] = "utenti";

    $_CONFIG['expire'] = 60;
    $_CONFIG['check_table'] = array(
    "username" => "check_username",
    "password" => "check_global",
    "name" => "check_global",
    "surname" => "check_global",
    "indirizzo" => "check_global",
    "occupazione" => "check_global",
    "mail" => "check_global"
    );

    function check_username($value){
    global $_CONFIG;
    $value = trim($value);
    if($value == "")
    return "Il campo non può essere lasciato vuoto";
    $query1 = "SELECT id FROM utenti WHERE username='".$value."'";
    echo "errore: .$result.";
    $result= connessione($queryl);
    echo "errore: .$result.";
    $count=mysql_num_rows($result);
    if(mysql_num_rows($count) != 0)
    return "Nome utente già utilizzato";
    return true;
    }

    function check_global($value){
    global $_CONFIG;
    $value = trim($value);
    if($value == "")
    return "Il campo non può essere lasciato vuoto";
    return true;
    }


    function connessione($sql)
    {
    $dbuser="root";
    $dbpass="root";
    $dbname="accessi";
    $dbhost="localhost";
    $connessione=mysql_connect($dbhost,$dbuser,$dbpass ) or die("Connessione non riuscita: " . mysql_error());
    mysql_select_db($dbname) or die("Selezione del database non riuscita");
    $rs=mysql_query($sql) or die ("errore query");
    return $rs;


    }

    function closeconnessione($result)
    {
    mysql_free_result($result);
    }


    L'errore che mi da è ("errore query"); della funzione di connessione!!

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.