Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2008
    Messaggi
    11

    problema login,utente si disconnette

    salve,
    voglio esporvi il mio problema.

    sto seguendo questa guida http://php.html.it/articoli/leggi/90...tenti-con-php/

    per poter implementare un semplice login sul mio sito.

    non capisco perche una volta connesso dopo un minuto (mi dicono anche subito appena clicchi un altro link - alcuni amici che hanno provato) il menu ritorna ad essere come se non fossi loggato

    nella index.php ho
    Codice PHP:

    //vari tag html...div eccc  

    <?php include 'menu.php'?>

    //altri tag html

    il file menu.php (in questo file decido se fare visualizzare il menu per utente loggato o un altro menu)
    Codice PHP:
    <?php
    include_once("include/config.php"); 
    include_once(
    "include/auth.lib.php"); 
     list(
    $status$user) = auth_get_status(); 
     if(
    $status == AUTH_LOGGED){     

    $msg '<div id="menu04v">  <ul>[*][url="index.php"]Home[/url]   

    //qua c'
    è il resto del menu
    [*][url="logout.php"]Logout '.$user['name']. '[/url][/list]</div>'; 

    echo $msg; 

    }else    $msg =  '
    <div id="menu04v">  
    <
    ul>   

    //qua c'è un altro resto del menu
    [*][url="loginform.php"]Admin[/url] [/list]</div>';

     echo $msg;    ?>


    il login lo faccio cosi :

    loginform.php (questa è praticamente uguale alla guida)
    Codice PHP:
    <?php
    include_once("include/config.php");
    include_once(
    "include/auth.lib.php");

    list(
    $status$user) = auth_get_status();

    if(
    $status == AUTH_LOGGED auth_get_option("TRANSICTION METHOD") == AUTH_USE_LINK){
        
    $link "?uid=".$_GET['uid'];
    }else    
    $link '';
    ?>


            <?php
            
    switch($status){
                case 
    AUTH_LOGGED:
                
    ?>
                [b]Sei loggato con il nome di <?=$user["name"];?> [url="logout.php<?=$link?>"]Logout[/url][/b]
                <?php
                
    break;
                case 
    AUTH_NOT_LOGGED:
                
    ?>
            <form action="login.php<?=$link?>" method="post">
                <table cellspacing="2">
                    <tr>
                        <td>Nome Utente:</td>
                        <td><input type="text" name="uname"></td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><input type="password" name="passw"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="action" value="login"></td>
                    </tr>
                    <tr>
                        <td>

    Effettuando il login vedrai funzioni aggiuntive nel menu'

                        Come prova ho impostato un utente:  Username:admin   password: admin
                        </td>
                    </tr>
                </table>
            </form>
            <?php
                
    break;
            }
            
    ?>



    ora non capisco perche una volta fatto il login mi rimane collegato e mi fa vedere il menu giusto(cambiato) e dopo tipo un minuto che non faccio niente, vado su index.php e

    - vedo il menu come se non fossi loggato
    - mi esce questo warning

    modify header information - headers already sent by (output started at /var/www/html/garage/index.php:12) in /var/www/html/garage/include/auth.lib.php on line 31

    grazie per i consigli,

    se volete altre spegazioni sono pronto... nn so che puo essere

    (non so se sbaglio nel file login.php)
    login.php (dalla guida ho cambiato i vai header(...) e ho messo di puntare a index.php)
    Codice PHP:
    <?php
    include_once("include/config.php");
    include_once(
    "include/auth.lib.php");

    list(
    $status$user) = auth_get_status();

    if(
    $status == AUTH_NOT_LOGGED){
        
    $uname strtolower(trim($_POST['uname']));
        
    $passw strtolower(trim($_POST['passw']));

        if(
    $uname == "" or $passw == ""){
            
    $status AUTH_INVALID_PARAMS;
        }else{
            list(
    $status$user) = auth_login($uname$passw);
            if(!
    is_null($user)){
                list(
    $status$uid) = auth_register_session($user);
            }
        }
    }

    switch(
    $status){
        case 
    AUTH_LOGGED:
            
    header("Refresh: 5;URL=index.php");
            echo 
    '<div align="center">Sei gia connesso ... attendi il reindirizzamento</div>';
        break;
        case 
    AUTH_INVALID_PARAMS:
            
    header("Refresh: 5;URL=index.php");
            echo 
    '<div align="center">Hai inserito dati non corretti ... attendi il reindirizzamento</div>';
        break;
        case 
    AUTH_LOGEDD_IN:
            switch(
    auth_get_option("TRANSICTION METHOD")){
                case 
    AUTH_USE_LINK:
                    
    header("Refresh: 5;URL=index.php?uid=".$uid);
                break;
                case 
    AUTH_USE_COOKIE:
                    
    header("Refresh: 5;URL=index.php");
                    
    setcookie('uid'$uid0);//time()+3600*365);
                
    break;
                case 
    AUTH_USE_SESSION:
                    
    header("Refresh: 5;URL=index.php");
                    
    $_SESSION['uid'] = $uid;
                break;
            }
            echo 
    '<div align="center">Ciao '.$user['name'].' ... attendi il reindirizzamento</div>';
        break;
        case 
    AUTH_FAILED:
            
    header("Refresh: 5;URL=index.php");
            echo 
    '<div align="center">Fallimento durante il tentativo di connessione ... attendi il reindirizzamento</div>';
        break;
    }
    ?>


    LO so è un post un po pesantuccio :P

  2. #2
    posta anche

    include/config.php
    include/auth.lib.php

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2008
    Messaggi
    11
    Codice PHP:
    <?php
    $_CONFIG
    ['host'] = "localhost";
    $_CONFIG['user'] = "******";
    $_CONFIG['pass'] = "********";
    $_CONFIG['dbname'] = "miodb";

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

    $_CONFIG['expire'] = 60;


    //--------------
    define('AUTH_LOGGED'99);
    define('AUTH_NOT_LOGGED'100);

    define('AUTH_USE_COOKIE'101);
    define('AUTH_USE_LINK'103);
    define('AUTH_INVALID_PARAMS'104);
    define('AUTH_LOGEDD_IN'105);
    define('AUTH_FAILED'106);

    $conn mysql_connect($_CONFIG['host'], $_CONFIG['user'], $_CONFIG['pass']) or die('Impossibile stabilire una connessione');
    mysql_select_db($_CONFIG['dbname']);
    ?>


    Codice PHP:
    <?php

    $_AUTH 
    = array(
        
    "TRANSICTION METHOD" => AUTH_USE_COOKIE
    );

    function 
    auth_set_option($opt_name$opt_value){
        global 
    $_AUTH;
        
        
    $_AUTH[$opt_name] = $opt_value;
    }

    function 
    auth_get_option($opt_name){
        global 
    $_AUTH;
        
        return 
    is_null($_AUTH[$opt_name])
            ? 
    NULL
            
    $_AUTH[$opt_name];
    }

    function 
    auth_clean_expired(){
        global 
    $_CONFIG;
        
        
    $result mysql_query("SELECT creation_date FROM ".$_CONFIG['table_sessioni']." WHERE uid='".auth_get_uid()."'");
        if(
    $result){
            
    $data mysql_fetch_array($result);
            if(
    $data['creation_date']){
                if(
    $data['creation_date'] + $_CONFIG['expire'] <= time()){
                    switch(
    auth_get_option("TRANSICTION METHOD")){
                        case 
    AUTH_USE_COOKIE:
                            
    setcookie('uid');
                        break;
                        case 
    AUTH_USE_LINK:
                            global 
    $_GET;
                            
    $_GET['uid'] = NULL;
                        break;
                    }
                }
            }
        }
        
        
    mysql_query("
        DELETE FROM "
    .$_CONFIG['table_sessioni']."
        WHERE creation_date + "
    .$_CONFIG['expire']." <= ".time()
        );
    }

    function 
    auth_get_uid(){
        
        
    $uid NULL;

        switch(
    auth_get_option("TRANSICTION METHOD")){
            case 
    AUTH_USE_COOKIE:
                global 
    $_COOKIE;
                
    $uid $_COOKIE['uid'];
            break;
            case 
    AUTH_USE_LINK:
                global 
    $_GET;
                
    $uid $_GET['uid'];
            break;
        }

        return 
    $uid $uid NULL;
    }

    function 
    auth_get_status(){
        global 
    $_CONFIG;

        
    auth_clean_expired();
        
    $uid auth_get_uid();
        if(
    is_null($uid))
            return array(
    100NULL);
        
        
    $result mysql_query("SELECT U.name as name, U.surname as surname, U.username as username
        FROM "
    .$_CONFIG['table_sessioni']." S,".$_CONFIG['table_utenti']." U
        WHERE S.user_id = U.id and S.uid = '"
    .$uid."'");
        
        if(
    mysql_num_rows($result) != 1)
            return array(
    100NULL);
        else{
            
    $user_data mysql_fetch_assoc($result);
            return array(
    99array_merge($user_data, array('uid' => $uid)));
        }
    }

    function 
    auth_login($uname$passw){
        global 
    $_CONFIG;

        
    $result mysql_query("
        SELECT *
        FROM "
    .$_CONFIG['table_utenti']."
        WHERE username='"
    .$uname."' and password=MD5('".$passw."')"
        
    );
        
        if(
    mysql_num_rows($result) != 1){
            return array(
    AUTH_INVALID_PARAMSNULL);
        }else{
            
    $data mysql_fetch_array($result);
            return array(
    AUTH_LOGEDD_IN$data);
        }
    }

    function 
    auth_generate_uid(){

        list(
    $usec$sec) = explode(' 'microtime());
        
    mt_srand((float) $sec + ((float) $usec 100000));
        return 
    md5(uniqid(mt_rand(), true));
    }

    function 
    auth_register_session($udata){
        global 
    $_CONFIG;
        
        
    $uid auth_generate_uid();
        
        
    mysql_query("
        INSERT INTO "
    .$_CONFIG['table_sessioni']."
        (uid, user_id, creation_date)
        VALUES
        ('"
    .$uid."', '".$udata['id']."', ".time().")
        "
        
    );
        if(!
    mysql_insert_id()){
            return array(
    AUTH_LOGEDD_IN$uid);
        }else{
            return array(
    AUTH_FAILEDNULL);
        }
    }

    function 
    auth_logout(){
        global 
    $_CONFIG;

        
    $uid auth_get_uid();
        
        if(
    is_null($uid)){
            return 
    false;
        }else{
            
    mysql_query("
            DELETE FROM "
    .$_CONFIG['table_sessioni']."
            WHERE uid = '"
    .$uid."'"
            
    );
            return 
    true;
        }
    }
    ?>

    ecco i due files...
    sono quelli che ho scaricato con la guida comunque.

    grazie se mi potete dare una mano

  4. #4
    l'errore

    modify header information - headers already sent by (output started at /var/www/html/garage/index.php:12) in /var/www/html/garage/include/auth.lib.php on line 31

    significa che c'è ad esempio un tentativo di suare l'istruzione HEADER nel bel mezzo della pagina quando invece deve essere inviato prima delle intestazioini normali di una pagina hTML; quindi controlla auth.lib.php in riga 31 come dice l'errore

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2012
    Messaggi
    104
    Io ho esattametne lo stesso problema, ovvero si disconnette entro 1 minuto, anche se non mi da nessun tipo di errore. Potrei sapere se avete risolto il problema e come?
    Grazie

  6. #6
    Utente di HTML.it L'avatar di Secta
    Registrato dal
    May 2002
    Messaggi
    365
    Ammetto di non aver letto il codice... ma mentre scorrevo la pagina l'occhio mi è caduto su

    Codice PHP:
    $_CONFIG['expire'] = 60
    che sia questo il problema? cambia il valore e vedi che succede.
    "Dai diamanti non nasce niente, dal letame nascon fiori."
    Fabrizio De Andrè

  7. #7
    Utente di HTML.it
    Registrato dal
    Feb 2012
    Messaggi
    104
    Ci avevo fatto caso anche io, anche se l'expire è richiamato solo per cancellare dal database chi non risponde alla conferma della registrazione. Cmq provar non nuoce. Stasera provo e ti aggiorno. Grazie

  8. #8
    Utente di HTML.it
    Registrato dal
    Feb 2012
    Messaggi
    104
    Pazzesco, era proprio quello, ora ho messo 3600. Grazie

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.