Pagina 2 di 4 primaprima 1 2 3 4 ultimoultimo
Visualizzazione dei risultati da 11 a 20 su 31

Discussione: Login di accesso

  1. #11
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    539
    ci sono anche altri errori:

    Codice PHP:
    if($key){$pagina $arrPagina[$key]; }{ 
    dovrebbe essere

    Codice PHP:
    if($key){
       
    $pagina $arrPagina[$key]; 
    }

    per cui la domanda è: l'ultima graffa che ci sta a fare?

    inoltre fai un redirect (header) e poi scrivi in un file...ma se fai un redirect come può scrivere nel file?

    Codice PHP:
    header("Location: " $pagina ".html");


    // questo programma registra tutti gli utenti che entrano in un apposito file
    $filename "cronologiautenti.txt";
    $testo $_POST['user']." ".$data."
    "
    ;
    $handle fopen($filename'a');
    fwrite($handle$testo);
    fclose($handle); 
    sempre a proposito di redirect,
    il tuo array è:

    Codice PHP:
    $arrPagina = array('home.html''home.html''home2.html'); 
    e la tua redirect in caso di indice 0, cioè il primo valore dell'array, risulterebbe:

    Codice PHP:
    header("Location: " $pagina ".html"); 
    il primo valore dell'array è "home.html", avendolo assegnato alla variabile $pagina, il tuo header sarebbe:

    Codice PHP:
    header("Location: home.html.html"); 
    rivedi un pò tutto il codice...

  2. #12
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    Vabb continuate ad impazzire su quel codice assolutamente non ingenierizzato e poco gestibile.

    Ciau.

  3. #13
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    539
    Originariamente inviato da Virus_101
    Vabb continuate ad impazzire su quel codice assolutamente non ingenierizzato e poco gestibile.

    Ciau.
    così almeno lo capisce, mi pare di capire che ne mastica poco...

  4. #14
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    Si vero cmq per come la vedo io il mio codice e' piu' pulito e gestibile, nonche' piu' corto e facilmente leggibile.

    Poi fate vobis.

  5. #15
    Originariamente inviato da Virus_101
    Si vero cmq per come la vedo io il mio codice e' piu' pulito e gestibile, nonche' piu' corto e facilmente leggibile.

    Poi fate vobis.
    Dopo aver passato una serata intera a impazzire senza nessun risultato (sempre lo stesso errore "Parse error: parse error in pr_00.php on line xx dove xx sta per un numero che ogni volta cambia)" ho provato il tuo codice.
    l'ho copiato così come me lo hai postato ma niente anche in questo caso stesso errore!
    Sarà pure corto e gestibile ma credimi non funziona. Ti prego aiutami!!!

    su file users.php
    Codice PHP:

    $users 
    = array(

         
    "gianni" => array(
                   
    "pwd" => "aiuhajksd" ,
                   
    "homepage" => "gianni_home.html" ,
                   
    "is_active" => true
              
    ),

         
    "marco" => array(
                   
    "pwd" => "aiasdsd" ,
                   
    "homepage" => "marco_home.html" ,
                   
    "is_active" => true
              
    ),

    ); 

    file ph_00.php

    Codice PHP:

    include("./users.php")

    $log $_POST["login"] ;
    $pwd $_POST["password"] ;

    $user =  $users["login"]

    if( 
    $user && $user["pwd"]==$pwd && user["is_active"]===true)
    {
         
    header("location:".$user["homepage"]);
    }
    else
    {die(
    "TU NON PUOI PASSSHARE !!! [cit]Gandalf[/cit] ");} 

  6. #16
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    Beh considera che il codice era scritto di getto ed effettivamente c'erano un paio di errori di sintassi.

    cmq partiamo dal primo file : users.php

    Codice PHP:
    $users = array(

         
    "gianni" => array(
                   
    "pwd" => "aiuhajksd" ,
                   
    "homepage" => "gianni_home.html" ,
                   
    "is_active" => true
              
    ),

         
    "marco" => array(
                   
    "pwd" => "aiasdsd" ,
                   
    "homepage" => "marco_home.html" ,
                   
    "is_active" => true
              
    )// RIMOSSA LA "," in piu'

    ); 

    file :login.php
    Codice PHP:

    $log 
    $_POST["login"] ;
    $pwd $_POST["password"] ;

    $user =  $users["login"] ;

    if( 
    $user && $user["pwd"]==$pwd && $user["is_active"]===true )
    {
         
    header("location:".$user["homepage"]);
    }
    else
    {die(
    "TU NON PUOI PASSSHARE !!! [cit]Gandalf[/cit] ");} 

    Questa come base di partenza. Poi dovremmo inserire la gestione delle sessioni per impedire l'accesso ai files e il file di log.

    Adesso ti preparo un paio di script testati.

  7. #17
    Originariamente inviato da freeman74
    ci sono anche altri errori:

    Codice PHP:
    if($key){$pagina $arrPagina[$key]; }{ 
    dovrebbe essere

    Codice PHP:
    if($key){
       
    $pagina $arrPagina[$key]; 
    }

    per cui la domanda è: l'ultima graffa che ci sta a fare?

    inoltre fai un redirect (header) e poi scrivi in un file...ma se fai un redirect come può scrivere nel file?

    Codice PHP:
    header("Location: " $pagina ".html");


    // questo programma registra tutti gli utenti che entrano in un apposito file
    $filename "cronologiautenti.txt";
    $testo $_POST['user']." ".$data."
    "
    ;
    $handle fopen($filename'a');
    fwrite($handle$testo);
    fclose($handle); 
    sempre a proposito di redirect,
    il tuo array è:

    Codice PHP:
    $arrPagina = array('home.html''home.html''home2.html'); 
    e la tua redirect in caso di indice 0, cioè il primo valore dell'array, risulterebbe:

    Codice PHP:
    header("Location: " $pagina ".html"); 
    il primo valore dell'array è "home.html", avendolo assegnato alla variabile $pagina, il tuo header sarebbe:

    Codice PHP:
    header("Location: home.html.html"); 
    rivedi un pò tutto il codice...


    freeman74 ci sono quasi! Non posso mollare proprio adesso!! Allora stamattina ho ripreso a lavorarci su e da prove effettuate l'errore mi viene segnalato sempre sulla riga 22 del file pr_00.php ti allego il codice:
    Ho provato anche ad inserire la stringa: header("Location: home.html.html"); ma non va!
    Grazie mille!!! A buon rendere!!


    Codice PHP:

    <?php


    $data
    =date("m.d.y, H:i:s");
    include(
    'database.php');
    if(
    in_array($_POST['user'],$datauser)){
    $valuser1;
    $chiaveuser array_search($_POST['user'], $datauser);
    }
    if(
    in_array($_POST['password'],$datapassword)){
    $valpassword1;
    $chiavepassword array_search($_POST['password'], $datapassword);
    }
    $valsomm$valuser+$valpassword;
    if((
    $valsomm==2)&&($chiavepassword==$chiaveuser)){

    $key array_search($_POST['user'],$datauser);
    if(
    $key){
       
    $pagina $arrPagina[$key];
    }

    header("Location: " $pagina ".html");    <-- QUESTA è LA RIGA 22 DOVE SEGNALA L'ERRORE



    }else{
    //invece qui ci devi mettere la pagina a che da errore nell inserimento del login
    include('
    errore.html');
    }
    ?>
    Allego anche il codice del file database.php

    Codice PHP:
    <?


    //Per chi lo ha scaricato: inserisci qui i nomi degli utenti
    $datauser = array('enzo','marco','matteo');
    //Qui le password
    $datapassword = array('enzo','marco','matteo');
    //ricordati che lil primo nick va con la prima password o cosi via
    $arrPagina = array('home.html''home1.html''home2.html'); 
    ?>

  8. #18
    Originariamente inviato da Virus_101
    Beh considera che il codice era scritto di getto ed effettivamente c'erano un paio di errori di sintassi.

    cmq partiamo dal primo file : users.php

    Codice PHP:
    $users = array(

         
    "gianni" => array(
                   
    "pwd" => "aiuhajksd" ,
                   
    "homepage" => "gianni_home.html" ,
                   
    "is_active" => true
              
    ),

         
    "marco" => array(
                   
    "pwd" => "aiasdsd" ,
                   
    "homepage" => "marco_home.html" ,
                   
    "is_active" => true
              
    )// RIMOSSA LA "," in piu'

    ); 

    file :login.php
    Codice PHP:

    $log 
    $_POST["login"] ;
    $pwd $_POST["password"] ;

    $user =  $users["login"] ;

    if( 
    $user && $user["pwd"]==$pwd && $user["is_active"]===true )
    {
         
    header("location:".$user["homepage"]);
    }
    else
    {die(
    "TU NON PUOI PASSSHARE !!! [cit]Gandalf[/cit] ");} 

    Questa come base di partenza. Poi dovremmo inserire la gestione delle sessioni per impedire l'accesso ai files e il file di log.

    Adesso ti preparo un paio di script testati.
    GRAZIE MILLE DI CUORE!!!
    cque ho provato il codice postato ma mi segnala errore alla riga 5 e cioè:

    $log = $_POST["login"] ;

    Grazie mille!

  9. #19
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    Ok allora il codice completo che potrai tranquillamente modificare si compone dei seguenti files :


    - users.php
    - functs.php
    - login.php
    - logout.php
    - checksession.php
    - index.html
    - test-home.html


    USERS.PHP
    Codice PHP:
    <?

    /*
        USERS DEFINITIONS FILE protect this with htaccess 
    */



    $users = array(

         
    "gianni" => array(
                   
    "pwd" => "aiuhajksd" ,
                   
    "homepage" => "gianni_home.php" ,
                   
    "is_active" => true
              
    ),
              
         
    "test" => array(
                   
    "pwd" => "test" ,
                   
    "homepage" => "test_home.php" ,
                   
    "is_active" => true
              
    ),

         
    "marco" => array(
                   
    "pwd" => "aiasdsd" ,
                   
    "homepage" => "marco_home.php" ,
                   
    "is_active" => true
              
    )

    );



    ?>
    FUNCTS.PHP
    Codice PHP:
    <?
    /* FUNCTS FILE */


    function logga($str)
    {
        
    $path "./logs/";
        
    // Create the log dir if not exists
        
    if( !file_exists($path) || !is_dir($path) )
        {
            
    mkdir($path);
            
    chmod($path 0777);
        }

        
    // Create the filename log , if file exists open in append mode
        
    $logFile $path.date"Y-m-d" time() )."_access_log.txt" ;
        
        
    $fp fopen($logFile,"a") ;
        
        if( !
    $fp )
        {    
    //IF fail to open or create file track the error
            
    return false ;
        }
        
    $str .= "\n" ;
        
    // Write content in the file
        
    fwrite$fp $str strlen($str) ) ;
        
    // Close the file
        
    fclose($fp);
        return 
    true;
    }



    ?>
    LOGIN.PHP
    Codice PHP:
    <?
    /*LOGIN FILE*/

    require_once("users.php") ;
    require_once(
    "functs.php") ;

    $lgn $_POST["login"] ;
    $pwd $_POST["password"] ;

    $user =  $users[$lgn] ;


    $uip   $_SERVER['REMOTE_ADDR'];
    $atime date"Y-m-d H:i:s" time() ) ; 
    $ua    $_SERVER["HTTP_USER_AGENT"] ;

    $str 
    "
    --------------------------------------------------------------------------------
    ["
    .$atime."] LOGIN ATTEMPT
    FROM : "
    .$uip."
    USER-AGENT : "
    .$ua."";

    if( 
    $user && $user["pwd"]==$pwd && $user["is_active"]===true )
    {
        
    $str .=
    "
    RESULT : data accepted => user "
    .$lgn."
    --------------------------------------------------------------------------------"
    ;

        
    // STARTUP AND STORE THE SESSION VARS FOR USER ACCESS CONTROLS
        
    session_start() ;
        
    $_SESSION["logged_user"] = $lgn ;
        
    // Trick to hide pwd data
        
    $_SESSION["logged_password"] = md5($pwd) ;
        if( !
    logga($str) )
        {
            
    session_unset();
            
    session_destroy();
            
    // IF LOG FAILS, FORBID USER ACCESS
            
    die("Impossibile gestire i dati di accesso") ;
        }
        
         
    header("location:".$user["homepage"]);
    }
    else
    {
    $str .=
    "
    RESULT : login failed => user "
    .$lgn." , used pwd => ".$pwd."
    --------------------------------------------------------------------------------"
    ;
        if( !
    logga($str) )
        {    
            die(
    "Impossibile gestire i dati di accesso") ;
        }

        die(
    "TU NON PUOI PASSSHARE !!! [cit]Gandalf[/cit] ");
    }

    ?>
    LOGOUT.PHP
    Codice PHP:
    <?

    session_start
    ();
    session_destroy();
    header("location:./index.html");
    die();

    ?>
    CHECKSESSION.PHP
    Codice PHP:
    <?


    require_once("./users.php") ;
    require_once(
    "./functs.php") ;



    session_start();
    $lgn $_SESSION["logged_user"] ;
    $pwd $_SESSION["logged_password"] ;
    $user =  $users[$lgn] ;

    if( !
    $user || md5($user["pwd"])!=$pwd || $user["is_active"]!==true )
    {
        
    header("location:./logout.php");
        die();
    }

    ?>
    INDEX.HTML
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
      <
    head>
      <
    meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <
    meta name="generator" content="PSPad editor, [url]www.pspad.com[/url]">
      <
    title></title>
      </
    head>
      <
    body>
    <
    form name="logga" action="./login.php" method="post">

    Login: <input type="text" name="login" />


    Password : <input type="password" name="password" />


    <
    input type="submit" value="login" />
    </
    form>
      </
    body>
    </
    html
    TEST_HOME.PHP
    Codice PHP:
    <?

    include("./checksession.php");

    // SPECIFIC USER ACCESS CONTROL
    if($_SESSION["logged_user"]!="test")
    { die(
    "NON PUOI ACCEDERE A QUESTA PAGINA"); }


    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <meta name="generator" content="PSPad editor, [url]www.pspad.com[/url]">
      <title></title>
      </head>
      <body><center>
    <h1 >PAGINA DI : TEST</h1>
    [url="./logout.php"]ESCI[/url]
    </center></body>
    </html>

    Provalo .... ciao.

  10. #20
    Originariamente inviato da Virus_101
    Ok allora il codice completo che potrai tranquillamente modificare si compone dei seguenti files :


    - users.php
    - functs.php
    - login.php
    - logout.php
    - checksession.php
    - index.html
    - test-home.html


    USERS.PHP
    Codice PHP:
    <?

    /*
        USERS DEFINITIONS FILE protect this with htaccess 
    */



    $users = array(

         
    "gianni" => array(
                   
    "pwd" => "aiuhajksd" ,
                   
    "homepage" => "gianni_home.php" ,
                   
    "is_active" => true
              
    ),
              
         
    "test" => array(
                   
    "pwd" => "test" ,
                   
    "homepage" => "test_home.php" ,
                   
    "is_active" => true
              
    ),

         
    "marco" => array(
                   
    "pwd" => "aiasdsd" ,
                   
    "homepage" => "marco_home.php" ,
                   
    "is_active" => true
              
    )

    );



    ?>
    FUNCTS.PHP
    Codice PHP:
    <?
    /* FUNCTS FILE */


    function logga($str)
    {
        
    $path "./logs/";
        
    // Create the log dir if not exists
        
    if( !file_exists($path) || !is_dir($path) )
        {
            
    mkdir($path);
            
    chmod($path 0777);
        }

        
    // Create the filename log , if file exists open in append mode
        
    $logFile $path.date"Y-m-d" time() )."_access_log.txt" ;
        
        
    $fp fopen($logFile,"a") ;
        
        if( !
    $fp )
        {    
    //IF fail to open or create file track the error
            
    return false ;
        }
        
    $str .= "\n" ;
        
    // Write content in the file
        
    fwrite$fp $str strlen($str) ) ;
        
    // Close the file
        
    fclose($fp);
        return 
    true;
    }



    ?>
    LOGIN.PHP
    Codice PHP:
    <?
    /*LOGIN FILE*/

    require_once("users.php") ;
    require_once(
    "functs.php") ;

    $lgn $_POST["login"] ;
    $pwd $_POST["password"] ;

    $user =  $users[$lgn] ;


    $uip   $_SERVER['REMOTE_ADDR'];
    $atime date"Y-m-d H:i:s" time() ) ; 
    $ua    $_SERVER["HTTP_USER_AGENT"] ;

    $str 
    "
    --------------------------------------------------------------------------------
    ["
    .$atime."] LOGIN ATTEMPT
    FROM : "
    .$uip."
    USER-AGENT : "
    .$ua."";

    if( 
    $user && $user["pwd"]==$pwd && $user["is_active"]===true )
    {
        
    $str .=
    "
    RESULT : data accepted => user "
    .$lgn."
    --------------------------------------------------------------------------------"
    ;

        
    // STARTUP AND STORE THE SESSION VARS FOR USER ACCESS CONTROLS
        
    session_start() ;
        
    $_SESSION["logged_user"] = $lgn ;
        
    // Trick to hide pwd data
        
    $_SESSION["logged_password"] = md5($pwd) ;
        if( !
    logga($str) )
        {
            
    session_unset();
            
    session_destroy();
            
    // IF LOG FAILS, FORBID USER ACCESS
            
    die("Impossibile gestire i dati di accesso") ;
        }
        
         
    header("location:".$user["homepage"]);
    }
    else
    {
    $str .=
    "
    RESULT : login failed => user "
    .$lgn." , used pwd => ".$pwd."
    --------------------------------------------------------------------------------"
    ;
        if( !
    logga($str) )
        {    
            die(
    "Impossibile gestire i dati di accesso") ;
        }

        die(
    "TU NON PUOI PASSSHARE !!! [cit]Gandalf[/cit] ");
    }

    ?>
    LOGOUT.PHP
    Codice PHP:
    <?

    session_start
    ();
    session_destroy();
    header("location:./index.html");
    die();

    ?>
    CHECKSESSION.PHP
    Codice PHP:
    <?


    require_once("./users.php") ;
    require_once(
    "./functs.php") ;



    session_start();
    $lgn $_SESSION["logged_user"] ;
    $pwd $_SESSION["logged_password"] ;
    $user =  $users[$lgn] ;

    if( !
    $user || md5($user["pwd"])!=$pwd || $user["is_active"]!==true )
    {
        
    header("location:./logout.php");
        die();
    }

    ?>
    INDEX.HTML
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
      <
    head>
      <
    meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <
    meta name="generator" content="PSPad editor, [url]www.pspad.com[/url]">
      <
    title></title>
      </
    head>
      <
    body>
    <
    form name="logga" action="./login.php" method="post">

    Login: <input type="text" name="login" />


    Password : <input type="password" name="password" />


    <
    input type="submit" value="login" />
    </
    form>
      </
    body>
    </
    html
    TEST_HOME.PHP
    Codice PHP:
    <?

    include("./checksession.php");

    // SPECIFIC USER ACCESS CONTROL
    if($_SESSION["logged_user"]!="test")
    { die(
    "NON PUOI ACCEDERE A QUESTA PAGINA"); }


    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <meta name="generator" content="PSPad editor, [url]www.pspad.com[/url]">
      <title></title>
      </head>
      <body><center>
    <h1 >PAGINA DI : TEST</h1>
    [url="./logout.php"]ESCI[/url]
    </center></body>
    </html>

    Provalo .... ciao.

    Mi da errore sulla riga 32 del file login.php e cioè alla voce:

    session_start() ;

    Perchè??

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 © 2026 vBulletin Solutions, Inc. All rights reserved.