Visualizzazione dei risultati da 1 a 10 su 10

Discussione: login multiutente

  1. #1
    Utente di HTML.it L'avatar di seingh
    Registrato dal
    Nov 2009
    Messaggi
    61

    login multiutente

    come posso realizzare un login multiutente in modo che ogni utente abbia la propia pagina e la possa modificare?
    io sono riuscito a creare solo un login form (e registrazione) ma i dati degli utenti sono sempre uguali
    help please

  2. #2
    Crei un database e sopra ci salvi i dati dei tuoi utenti.
    Poi ad ogni utente abbini una user e una password.
    In questo modo ogni utente può vedere solo i propri dati.


  3. #3
    Utente di HTML.it L'avatar di seingh
    Registrato dal
    Nov 2009
    Messaggi
    61
    fino a qui ci sono arrivato anch'io ma dopo non riesco a fare modificare la pagina all'utente per poi applicare le modifiche nel mio database mysql ti allego i miei file di login





    access-denied.php
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Access Denied</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1> <h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1><h1>Accesso negato </h1> <p align="center"></p> <h4 align="center" class="err">Accesso negato 
       Non hai i permessi per accedere
    </h4> </body> </html


    auth.php
    Codice PHP:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Check whether the session variable SESS_MEMBER_ID is present or not
        
    if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
            
    header("location: access-denied.php");
            exit();
        }
    ?>


    config.php
    Codice PHP:
    <?php
        define
    ('DB_HOST''xxxx');
        
    define('DB_USER''xxxxx');
        
    define('DB_PASSWORD''xxxxxxx');
        
    define('DB_DATABASE''xxxxx');
    ?>




    index.php

    Codice PHP:
    <style>
    #loading{
            
    position:absolute;
            
    width:200px;
            
    height:100px;
            
    left:300px;
            
    top:180px;
            
    z-index:1;
            
    background-color#6B718B;
            
    font:40px Times new romanHelveticasans-serif;
            
    color:#ffffff;
            
    padding:20px;
    }
    </
    style>
    <
    div id="loading">Caricamento...</div>
    <
    script>
    function 
    finish(){
        
    document.getElementById("loading").style.visibility "hidden";
    }
    </script>
    <body onload="finish()">
    <link href="loginmodule.css" rel="stylesheet" type="text/css" />
    <h1>Benvenuto</h1>
    <h4>login [url="login-form.php"]qui[/url]|registrati [url="register-form.php"]qui[/url] 


    login-exec.php
    Codice PHP:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Include database connection details
        
    require_once('config.php');
        
        
    //Array to store validation errors
        
    $errmsg_arr = array();
        
        
    //Validation error flag
        
    $errflag false;
        
        
    //Connect to mysql server
        
    $link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
        if(!
    $link) {
            die(
    'Failed to connect to server: ' mysql_error());
        }
        
        
    //Select database
        
    $db mysql_select_db(DB_DATABASE);
        if(!
    $db) {
            die(
    "Unable to select database");
        }
        
        
    //Function to sanitize values received from the form. Prevents SQL injection
        
    function clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }
        
        
    //Sanitize the POST values
        
    $login clean($_POST['login']);
        
    $password clean($_POST['password']);
        
        
    //Input Validations
        
    if($login == '') {
            
    $errmsg_arr[] = 'Login ID persa';
            
    $errflag true;
        }
        if(
    $password == '') {
            
    $errmsg_arr[] = 'Password persa';
            
    $errflag true;
        }
        
        
    //If there are input validations, redirect back to the login form
        
    if($errflag) {
            
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            
    session_write_close();
            
    header("location: login-form.php");
            exit();
        }
        
        
    //Create query
        
    $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
        
    $result=mysql_query($qry);
        
        
    //Check whether the query was successful or not
        
    if($result) {
            if(
    mysql_num_rows($result) == 1) {
                
    //Login Successful
                
    session_regenerate_id();
                
    $member mysql_fetch_assoc($result);
                
    $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
                
    $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
                
    $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
                
    session_write_close();
                
    header("location: member-index.php");
                exit();
            }else {
                
    //Login failed
                
    header("location: login-failed.php");
                exit();
            }
        }else {
            die(
    "Query failed");
        }
    ?>





    login-failed.php
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>Login Failed</title>
    <
    link href="loginmodule.css" rel="stylesheet" type="text/css" />
    </
    head>
    <
    body>
    <
    h1>Login fallito</h1>
    <
    p align="center"></p>
    <
    h4 align="center" class="err">Login Fallito

      Controlla la tua username e
    /o la tua password</h4>
    </
    body>
    </
    html



    loginmodule.css
    Codice PHP:
    body {
        
    font11px VerdanaArialHelveticasans-serif;
        
    colorFF0000;
        
    margin0px;
        
    padding20px 10px 0px;
    }
    .
    textfield {
        
    font-size11px;
        
    colorFF0000;
        
    background#F7F7F7;
        
    border1px solid #CCCCCC;
        
    padding-left1px;
    }
    h1 {
        
    color#99CC00;
        
    margin0px 0px 5px;
        
    padding0px 0px 3px;
        
    fontbold 18px VerdanaArialHelveticasans-serif;
        
    border-bottom1px dashed #E6E8ED;
    }
    {
        
    color#2D3954;
        
    font-size11px;
    }
    a:hover {
        
    color#99CC00;
    }
    .
    err {
        
    color#FF9900;
    }
    th {
        
    font-weightbold;
        
    text-alignleft;




    logout.php
    Codice PHP:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Unset the variables stored in session
        
    unset($_SESSION['SESS_MEMBER_ID']);
        unset(
    $_SESSION['SESS_FIRST_NAME']);
        unset(
    $_SESSION['SESS_LAST_NAME']);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Logged Out</title>
    <link href="loginmodule.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <h1>Logout </h1>
    <p align="center"></p>
    <h4 align="center" class="err">logout eseguito</h4>
    <p align="center">clicca qui per il [url="login-form.php"]Login[/url]</p>
    </body>
    </html>




    register-exec.php
    Codice PHP:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Include database connection details
        
    require_once('config.php');
        
        
    //Array to store validation errors
        
    $errmsg_arr = array();
        
        
    //Validation error flag
        
    $errflag false;
        
        
    //Connect to mysql server
        
    $link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
        if(!
    $link) {
            die(
    'Failed to connect to server: ' mysql_error());
        }
        
        
    //Select database
        
    $db mysql_select_db(DB_DATABASE);
        if(!
    $db) {
            die(
    "Unable to select database");
        }
        
        
    //Function to sanitize values received from the form. Prevents SQL injection
        
    function clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }
        
        
    //Sanitize the POST values
        
    $fname clean($_POST['fname']);
        
    $lname clean($_POST['lname']);
        
    $login clean($_POST['login']);
        
    $password clean($_POST['password']);
        
    $cpassword clean($_POST['cpassword']);
        
        
    //Input Validations
        
    if($fname == 'bill') {
            
    $errmsg_arr[] = 'tu non ti chiami bill gates';
            
    $errflag true;
        }
        if(
    $lname == 'gates') {
            
    $errmsg_arr[] = 'sisi e io sono tua nonna XDDDD';
            
    $errflag true;
        }
        if(
    $login == '') {
            
    $errmsg_arr[] = 'Non hai inserito la tua login id';
            
    $errflag true;
        }
        if(
    $password == '') {
            
    $errmsg_arr[] = 'Non hai inserito la tua password';
            
    $errflag true;
        }
        if(
    $cpassword == '') {
            
    $errmsg_arr[] = 'Non hai la conferma password';
            
    $errflag true;
        }
        if( 
    strcmp($password$cpassword) != ) {
            
    $errmsg_arr[] = 'Le password non corrispondono';
            
    $errflag true;
        }
        
        
    //Check for duplicate login ID
        
    if($login != '') {
            
    $qry "SELECT * FROM members WHERE login='$login'";
            
    $result mysql_query($qry);
            if(
    $result) {
                if(
    mysql_num_rows($result) > 0) {
                    
    $errmsg_arr[] = 'Login ID already in use';
                    
    $errflag true;
                }
                @
    mysql_free_result($result);
            }
            else {
                die(
    "Query failed");
            }
        }
        
        
    //If there are input validations, redirect back to the registration form
        
    if($errflag) {
            
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            
    session_write_close();
            
    header("location: register-form.php");
            exit();
        }

        
    //Create INSERT query
        
    $qry "INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','".md5($_POST['password'])."')";
        
    $result = @mysql_query($qry);
        
        
    //Check whether the query was successful or not
        
    if($result) {
            
    header("location: register-success.php");
            exit();
        }else {
            die(
    "Query failed");
        }
    ?>




    register-form.php
    Codice PHP:
    <?php
        session_start
    ();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Login Form</title>
    <link href="loginmodule.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <?php
        
    if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >) {
            echo 
    '<ul class="err">';
            foreach(
    $_SESSION['ERRMSG_ARR'] as $msg) {
                echo 
    '[*]',$msg,''
            }
            echo 
    '[/list]';
            unset(
    $_SESSION['ERRMSG_ARR']);
        }
    ?>
    <form id="loginForm" name="loginForm" method="post" action="register-exec.php">
      <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
        <tr>
          <th>Nome (non obligatorio)</th>
          <td><input name="fname" type="text" class="textfield" id="fname" /></td>
        </tr>
        <tr>
          <th>cognome (non obligatorio)</th>
          <td><input name="lname" type="text" class="textfield" id="lname" /></td>
        </tr>
        <tr>
          <th width="124">Login id (username)</th>
          <td width="168"><input name="login" type="text" class="textfield" id="login" /></td>
        </tr>
        <tr>
          <th>Password</th>
          <td><input name="password" type="password" class="textfield" id="password" /></td>
        </tr>
        <tr>
          <th>Ripeti password </th>
          <td><input name="cpassword" type="password" class="textfield" id="cpassword" /></td>
        </tr>
        <tr>
          <td></td>
          <td><input type="submit" name="Submit" value="Register" /></td>
        </tr>
      </table>
    </form>
    </body>
    </html>








    register-success.php
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>Registration Successful</title>
    <
    link href="loginmodule.css" rel="stylesheet" type="text/css" />
    </
    head>
    <
    body>
    <
    h1>Registrazione completata</h1>


    [
    url="login-form.php"]Clicca qui[/url]per loggarti</p>
    </
    body>
    </
    html




    gli utenti che possiedo ora (per prova) sono seingh (con la rispettiva password) e leizaR (con la rispettiva password)

  4. #4
    TOGLI IMMEDIATAMENTE QUESTO SCRPT DA QUA SOPRA!!!!!!!!!!!!!!

  5. #5
    Utente di HTML.it L'avatar di telegio
    Registrato dal
    Sep 2001
    Messaggi
    2,591
    hai messo trooooppo codice.. nessuno si metterà a guardarselo tutto..
    comunque manca la pagina che è quella in cui devi modificare i dati che dici.. non ce n'è traccia tra le cose che hai messo.
    la domanda fondamentale è:
    l'utente si logga? se si, devi prendere l'username col quale si logga, CHE DEVE ESSERE UNICO, che recuperi dal nome utente che ha inserito in fase di login e lo salvi in sessione.
    Da quello devi fare una query tipo select * from utente where username = '$username'.
    dopodichè ti stampi a video i risultati di questa query e nel caso fai le modifiche.

  6. #6
    digli anche te di cancellare lo script sopra... guarda bene cosa ha postato!!!

  7. #7
    Utente di HTML.it L'avatar di seingh
    Registrato dal
    Nov 2009
    Messaggi
    61
    ok lo tolgo ma xke?

    Edit: mi esce che nn posso editare il messaggio

  8. #8
    ci sono i tuoi dati di connessione al db!!!

  9. #9
    Utente di HTML.it L'avatar di seingh
    Registrato dal
    Nov 2009
    Messaggi
    61
    é vero XD
    gli admin non possono rimuoverli?
    xke a me esce scritto che nn posso modificarlo

  10. #10
    Utente di HTML.it L'avatar di seingh
    Registrato dal
    Nov 2009
    Messaggi
    61
    raga ho capito come farlo... ma adesso nn ho capito una cosa... come faccio a fare che l'utente lo puó modificare e che li puó visualizzare

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.