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

    problema con sessioni per la modifica anagrafica utenti

    salve a tutti,

    ho un problema con l'aggiornamento dell'anagrafica di utenti registrati ad un sito.
    cercherò di essere più precisa. utilizzo le sessioni per accedere alle pagine visibili solo ad utenti registrati, e fin qui tutto bene. il problema sorge quando un utente registrato accede e va nella sezione relativa alla modifica dei propri dati. il problema è che l'aggiornamento se sono tutti i campi compilati lo fa e poi chide nuovamente la login. il problema con le sessioni sorge quando ad esempio cancellano l'indirizzo email e lasciano il campo vuoto, la sessione viene chiusa e non dovrebbe.

    magari se qualcuno può darmi una mano vi posto il codice che può esservi più utile per analizzare il problema.. grazie mille a tutti

  2. #2

  3. #3
    ciao, come richiesto ti posto il codice della login:

    $msg=$_GET['msg'];
    $testo=$_GET['testo'];
    $testo=stripslashes($testo);
    $testo=htmlentities($testo);
    ?>
    <form action="checkuser.php" method="post" name="form1">

    <p align="center">
    <?if ($msg<>""){echo "<center>

    <font color=red>$msg</font></center></p>
    ";}?>
    <?if ($testo<>""){echo "<center>

    <font color=red>$testo</font></center></p>
    ";}?>
    <center> [img]img/accesso.png[/img]</p>
    </center>

    <table border="1" align="center" cellpadding="4" cellspacing="0" frames=all rules=none class=login>

    <tr bgcolor="#EAC5EA">
    <td width="45%">Username</td>
    <td width="55%"><input name="username" type="text" id="username" size="20"></td>
    </tr>
    <tr bgcolor="#EAC5EA">
    <td>Password</td>
    <td><input name="password" type="password" id="password" size="20"></td>
    </tr>
    <tr bgcolor="#EAC5EA">
    <td colspan=2 align="center"><input type="submit" name="Submit" value="Accedi"></td>
    </tr>
    </table>

    </form>

    ************************ checkuser *************

    <?
    /* Check User Script */
    session_start(); // Start Session

    include 'config.php';
    // Convert to simple variables
    $username = $_POST['username'];
    $password = $_POST['password'];

    if((!$username) || (!$password)){

    header("Location: index.php?page=login_page.php&msg=Attenzione, è necessario inserire tutte le informazioni");
    exit();
    }
    //echo("$password");
    // Convert password to md5 hash
    $password = md5($password);
    //die("$password");
    // check if the user info validates the db
    $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND attivo='1'");
    $login_check = mysql_num_rows($sql);

    if($login_check > 0){
    while($row = mysql_fetch_array($sql)){
    foreach( $row AS $key => $val ){
    $$key = stripslashes( $val );
    }

    // Register some session variables!
    //session_register('nome');
    $_SESSION['nome'] = $nome;
    //session_register('cognome');
    $_SESSION['cognome'] = $last_name;
    //session_register('email');
    $_SESSION['mail'] = $email_address;
    //session_register('profilo');
    $_SESSION['profilo'] = $profilo;
    $_SESSION['username']=$username;

    if ($profilo=="A")
    {
    header("Location: index.php?page=welcome_a.php");
    }
    else
    {
    if ($profilo=="P")
    {
    header("Location: index.php?page=welcome_p.php");
    }
    else
    {
    header("Location: index.php?page=welcome_c.php");
    }
    }
    }
    } else {
    //echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!
    Please try again!
    ";
    header("Location: index.php?page=login_page.php&msg=Attenzione, Username o Password errata.");
    //include 'login_page.php';
    }
    ?>

    grazie

  4. #4
    Alcune note generali:

    1. Non usare lo short open tag, utilizza il tag di apertura completo (<?php).
    2. Non accedere ad una variabile (es. un indice di un array superglobale) se non sei sicura che esista (vedi http://kb.creativepark.it/kb/entry/6/).
    3. Un header location richiede un URL assoluto.
    4. I parametri di un URL dovrebbero essere codificati correttamente (vedi http://www.php.net/urlencode).
    5. Dovresti rivedere attentamente le problematiche relative alla sicurezza come SQL Injection (vedi http://php.html.it/guide/leggi/121/g...urezza-di-php/).
    6. L'utilizzo del codice all'interno del while ($$key etc,) potrebbe introdurre un buco di sicurezza
    7. Prima di utilizzare il valore di ritorno di mysql_query() dovresti verificarne la correttezza.
    8. Quando devi utilizzare un header location con le sessioni, dovresti forzare il salvataggio dei dati (vedi http://kb.creativepark.it/kb/entry/5/).
    9. Per quale motivo utilizzi 3 diversi script di welcome.php?

    Per il resto, posta il codice che utilizzi per verificare il fatto che l'utente è loggato.

  5. #5
    intanto grazie per le note generali... ti posto il codice del form di modifica anagrafica, in cima c'è la if che verifica se l'utente è loggato:

    <?php
    /*session_start();*/
    include("config.php");
    echo("da sessione-");
    echo $_SESSION['username'];
    echo $_SESSION['nome'];

    $testo=$_GET['testo'];
    $testo=stripslashes($testo);
    $testo=htmlentities($testo);


    if ( empty($_SESSION['username'] ) ) {
    //echo "Accedi al sito!";
    include 'login_page.php';
    //header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php");


    } else {
    if ($testo!="") {
    echo("<center><font color=red>$testo</font></center>");

    }
    $username=$_SESSION['username'];
    $email_ok=$_SESSION['email_address'];
    //echo $_SESSION['email_address'];

    //echo("-$username - username - $email_ok -emailnow");
    $mod_anagrafica="select userid,nome, cognome, email, username, info FROM users WHERE username='$username' AND attivo='1'";
    $mod_anagrafica2=mysql_query($mod_anagrafica);
    //die($mod_anagrafica);
    while(list($id, $nome, $cognome, $email, $username, $info)=mysql_fetch_row($mod_anagrafica2))
    {
    ?>
    <form action="index.php?page=mod_profilo.php" method="post">
    <input type="hidden" name="id" value="<?echo("$id");?>">
    <table border=0 align=center cellpadding=2 cellspacing=0 id=contatti>
    <tr><td colspan=2 align=center>[img]img/mod_anagrafica.png[/img]

    </td></tr>
    <tr>
    <td align=left valign=top>Nome</td>
    <td align=left><input name=first_name type=text id=first_name2 value=<?echo("$nome")?>></td>
    </tr>
    <tr>
    <td align="left" valign="top">Cognome</td>
    <td align=left><input name=last_name type=text id=last_name value=<?echo("$cognome")?>></td>
    </tr>
    <tr>
    <td align=left valign=top>Email</td>
    <td><input name=email_address type=text id=email_address size=53 value=<?echo("$email")?>></td>
    <input name=email_address_old type=hidden id=email_address_old value=<?echo("$email")?>>
    </tr>
    <tr>
    <td align=left valign=top>Username</td>
    <td align="left"><input name=username disabled type=text id=username value="<?echo("$username");?>"></td>
    <input name=username_old type=hidden id=username_old value="<?echo("$username");?>">
    <input name=username type=hidden id=username value="<?echo("$username");?>">
    </tr>
    <tr>
    <td align=left valign=top>Informazioni aggiuntive:</td>
    <td><textarea name=info id=info cols=40 rows=8><?echo("$info")?></textarea></td></tr>
    <tr>
    <td colspan=2 align=center><input type=submit name=Submit value=Modifica></td>
    </tr>
    </table>
    </form>
    <? }
    }
    ?>

    *********************mod_profilo****************** **

    <?php
    //session_start();
    include 'config.php';

    if (!$_SESSION['email'])
    {
    $email_ses="prova@email.it";
    }
    else
    {
    $email_ses=$_SESSION['email'];
    }

    $user_now=$_POST['username_old'];

    /*echo("user da session ");
    echo $_SESSION['username'];
    */
    // Define post fields into simple variables
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email_address = $_POST['email_address'];
    $email_now = $_POST['email_address_old'];
    $username = $_POST['username'];
    $info = $_POST['info'];
    $id = $_POST['id'];


    /* Lets strip some slashes in case the user entered
    any escaped characters. */

    $first_name = stripslashes($first_name);
    $last_name = stripslashes($last_name);
    $email_address = stripslashes($email_address);
    $email_now = stripslashes($email_now);
    $username = stripslashes($username);

    $user_now=stripslashes($user_now);
    $info = stripslashes($info);
    $id = stripslashes($id);



    /* Do some error checking on the form posted fields */

    if((!$first_name) || (!$last_name) || (!$email_address) || (!$username))
    {
    //echo '

    Non hai inserito le seguenti informazioni necessarie alla modifica del profilo!</p>';
    if(!$first_name)
    {
    echo "

    Inserisci il Nome.</p>";
    }
    if(!$last_name)
    {
    echo "

    Inserisci il Cognome.</p>";
    }
    if(!$email_address)
    {
    echo "

    Inserisci il Email.</p>";
    //$errore="Inserisci Email!";
    }
    if(!$username)
    {
    echo "

    Inserisci la Username.</p>";
    }

    //echo("$email_now<>$email_address");
    //die("ENTRA IN IF NOT email_address-$email_address-");
    //header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php?page=gestione_profilo.php&testo=$errore" );

    include 'gestione_profilo.php'; // Show the form again!
    /* End the error checking and if everything is ok, we'll move on to
    creating the user account */
    //exit(); // if the error checking has failed, we'll exit the script
    }
    else
    {
    /* Let's do some checking and ensure that the user's email address or username
    does not exist in the database */


    if ($email_now<>$email_address)
    {
    $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email_address'");
    $email_check = mysql_num_rows($sql_email_check);
    }
    else
    {
    $email_check=0;
    }
    if ($user_now<>$username)
    {
    $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
    $username_check = mysql_num_rows($sql_username_check);
    }
    else
    {
    $username_check=0;
    }
    //echo("$email_check - $username_check");

    if(($email_check > 0) || ($username_check > 0))
    {
    echo "

    Errore: </p>";
    if($email_check > 0)
    {
    $errore="Attenzione l'email inserita è già utilizzata da un altro utente. Inserire un diverso indirizzo email!";
    //unset($email_address);
    }
    if($username_check > 0)
    {
    //echo "

    Attenzione la Username inserita è già utilizzata da un altro utente.\n Inserire una diversa Username!</p>";
    //unset($username);
    }
    //include 'gestione_profilo.php'; // Show the form again!
    header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php?page=gestione_profilo.php&testo=$errore" );

    //exit(); // exit the script so that we do not create this account!
    }
    else{




    $info2 = htmlspecialchars($info);
    $info2=addslashes($info2);
    $sql = mysql_query("update users set nome='$first_name', cognome='$last_name', email='$email_address', username='$username', info='$info2' where userid='$id' and attivo='1'") or die (mysql_error());


    $errore="Profilo Modificato con successo! Per rendere effettive le modifiche è necessario autenticarsi nuovamente!";
    header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php?page=login_page.php&testo=$errore");
    //exit();

    }}
    ?>

    ******************

    ho utilizzato diverse welcome a seconda del profilo.

    grazie x l'aiuto che mi stai dando.

  6. #6
    salve a tutti,
    se a qualcuno può tornare utile, vi dico che ho risolto il mio problema.
    avevo chiamato la variabile di sessione con lo stesso nome di altre variabili che utilizzavo in altre pagine.
    cambiando il nome delle variabili è andato tutto a posto.

    ciao a tutti

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.