• User Newbie

    session_start

    chi mi aiuta a risolvere questi errori?:(
    Notice: Undefined index: username in y:\home\login\www\index.php on line **88
    **Notice: Undefined index: username in y:\home\login\www\index.php on line 93

    Warning: Cannot modify header information - headers already sent by (output started at y:\home\login\www\index.php:88) in y:\home\login\www\index.php on line **143

    il codice è:
    <?php

    define('INCLUDE_CHECK',true);

    require 'connect.php';
    require 'functions.php';
    // Those two files can be included only if INCLUDE_CHECK is defined

    session_start();

    session_name('tzLogin');
    // Starting the session

    session_set_cookie_params(27246060);
    // Making the cookie live for 2 weeks

    if(isset($_SESSION['id']) && !isset($_COOKIE['tzRemember']) && !isset($_SESSION['rememberMe']))
    {
    // If you are logged in, but you don't have the tzRemember cookie (browser restart)
    // and you have not checked the rememberMe checkbox:

    $_SESSION = array();
    session_destroy();
    
    // Destroy the session
    

    }

    if(isset($_GET['logoff']))
    {
    $_SESSION = array();
    session_destroy();

    header("Location: index.php");
    exit;
    

    }

    if(isset($_POST['submit']) && $_POST['submit']=='Login')
    {
    // Checking whether the Login form has been submitted

    $err = array();
    // Will hold our errors
    
    
    if(!$_POST['username'] || !$_POST['password'])
        $err[] = 'All the fields must be filled in!';
    
    if(!count($err))
    {
        $_POST['username'] = mysql_real_escape_string($_POST['username']);
        $_POST['password'] = mysql_real_escape_string($_POST['password']);
        $_POST['rememberMe'] = (int)$_POST['rememberMe'];
        
        // Escaping all input data
    
        $row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));
    
        if($row['usr'])
        {
            // If everything is OK login
            
            $_SESSION['usr']=$row['usr'];
            $_SESSION['id'] = $row['id'];
            $_SESSION['rememberMe'] = $_POST['rememberMe'];
            
            // Store some data in the session
            
            setcookie('tzRemember',$_POST['rememberMe']);
        }
        else $err[]='Wrong username and/or password!';
    }
    
    if($err)
    $_SESSION['msg']['login-err'] = implode('<br />',$err);
    // Save the error messages in the session
    
    header("Location: index.php");
    exit;
    

    }
    else if(isset($_POST['submit']) && $_POST['submit']=='Register')
    {
    // If the Register form has been submitted

    $err = array();
    
    if(strlen($_POST['username'])<4 || strlen($_POST['username'])>32)
    {
        $err[]='Your username must be between 3 and 32 characters!';
    }
    
    if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['username']))
    {
        $err[]='Your username contains invalid characters!';
    }
    
    if(!checkEmail($_POST['email']))
    {
        $err[]='Your email is not valid!';
    }
    
    if(!count($err))
    {
        // If there are no errors
        
        $pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
        // Generate a random password
        
        $_POST['email'] = mysql_real_escape_string($_POST['email']);
        $_POST['username'] = mysql_real_escape_string($_POST['username']);
        // Escape the input data
        
        
        mysql_query("    INSERT INTO tz_members(usr,pass,email,regIP,dt)
                        VALUES(
                        
                            '".$_POST['username']."',
                            '".md5($pass)."',
                            '".$_POST['email']."',
                            '".$_SERVER['REMOTE_ADDR']."',
                            NOW()
                            
                        )");
        
        if(mysql_affected_rows($link)==1)
        {
            send_mail(    '[email protected]',
                        $_POST['email'],
                        'Registration System Demo - Your New Password',
                        'Your password is: '.$pass);
    
            $_SESSION['msg']['reg-success']='We sent you an email with your new password!';
        }
        else $err[]='This username is already taken!';
    }
    
    if(count($err))
    {
        $_SESSION['msg']['reg-err'] = implode('<br />',$err);
    }    
    
    header("Location: index.php");
    exit;
    

    }

    $script = '';

    if($_SESSION['msg'])
    {
    // The script below shows the sliding panel on page load

    $script = '
    <script type="text/javascript">
    
        $(function(){
        
            $("div#panel").show();
            $("#toggle a").toggle();
        });
    
    </script>';
    

    }
    ?>

    **


  • User Attivo

    Perchè fai riavviare il browser per settare il cookie?
    L'utente potrebbe considerarla una operazione malevola da parte di un cracker. Ma è una tua scelta. Io mostrerei una popup che richiede i dati da inserire nel cookie, per esempio.
    Forse fai eseguire session_destroy() prima di header("Location: index.php")


  • User Attivo

    Per il cookie: ricorri al cookie di sessione incorporando SID nella tua istruzione e se non puoi utilizzare il cookie nella macchina dell'utente in quanto non presente.
    Devi quindi usare $_COOKIE per verificare se tutti i valori che vuoi verificarne l'esiostenza nel cookie sulla macchina del tuo utente.
    Vedi il manuale online di PHP.