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

    [PHP] header location e ob_start

    Ciao a tutti ragazzi! come da titolo ho un pò di dubbi e problemi con la funzione
    header location

    quando eseguo il login di un utente
    Codice PHP:

      
    // inserisco in un oggetto i valori dell'utente dopo che il login
      // è andato a buon fine
      
    $loggedInUser = new loggedInUser();
      
    $loggedInUser->email $userdetails["Email"];
      
    $loggedInUser->user_id $userdetails["User_ID"];
      
    $loggedInUser->display_username $userdetails["Username"];
      
      
    // Aggiorno l'ultima visita
      
    $loggedInUser->updateLastSignIn();
      
      
    // inserisco il tutto nella sessione
      
    $_SESSION["userCakeUser"] = $loggedInUser;
      
      
    // Eseguo il redirect
      
    header("Location: account.php");
      die(); 
    Il problema è che se non metto ob_start(); all'inizio della pagina lo script non mi esegue il redirect, mi rimane nella pagina login.php in bianco e basta...

    Ma dove sta il problema? In locale mi funziona correttamente, sul server no...

    Vi ringrazio anticipatamente!!!

  2. #2
    c'è qualche output prima della funzione header? perché in tal caso non funzionerà.
    Il che avrebbe la sua logica col funzionamento di ob_start(), che attiva il buffering impedendone l'output
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  3. #3
    mmmm no non c'è nessun output.... anche se in realtà i controlli sono stati fatti nella stessa pagina in cui si trova il form...

  4. #4
    Originariamente inviato da webking2003
    mmmm no non c'è nessun output.... anche se in realtà i controlli sono stati fatti nella stessa pagina in cui si trova il form...
    cosa c'è prima del codice postato?
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  5. #5
    Codice PHP:
    if(!empty($_POST))
    {
            
    $errors = array();
            
    $username trim($_POST["username"]);
            
    $password trim($_POST["password"]);
        
            
    //Perform some validation
            //Feel free to edit / change as required
            
    if($username == "")
            {
                
    $errors[] = lang("ACCOUNT_SPECIFY_USERNAME");
            }
            if(
    $password == "")
            {
                
    $errors[] = lang("ACCOUNT_SPECIFY_PASSWORD");
            }
            
            
    //End data validation
            
    if(count($errors) == 0)
            {
                
    //A security note here, never tell the user which credential was incorrect
                
    if(!usernameExists($username))
                {
                    
    $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
                }
                else
                {
                    
    $userdetails fetchUserDetails($username);
                
                    
    //See if the user's account is activation
                    
    if($userdetails["Active"]==0)
                    {
                        
    $errors[] = lang("ACCOUNT_INACTIVE");
                    }
                    else
                    {
                        
    //Hash the password and use the salt from the database to compare the password.
                        
    $entered_pass generateHash($password,$userdetails["Password"]);

                        if(
    $entered_pass != $userdetails["Password"])
                        {
                            
    //Again, we know the password is at fault here, but lets not give away the combination incase of someone bruteforcing
                            
    $errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
                        }
                        else
                        {
                          
    // inserisco in un oggetto i valori dell'utente dopo che il login
                            // è andato a buon fine
                            
    $loggedInUser = new loggedInUser();
                            
    $loggedInUser->email $userdetails["Email"];
                            
    $loggedInUser->user_id $userdetails["User_ID"];
                            
    $loggedInUser->display_username $userdetails["Username"];
                            
                            
    // Aggiorno l'ultima visita
                            
    $loggedInUser->updateLastSignIn();
                            
                            
    // inserisco il tutto nella sessione
                            
    $_SESSION["userCakeUser"] = $loggedInUser;
                            
                            
    // Eseguo il redirect
                            
    header("Location: account.php");
                            die();
                          }
                    }
                }
            }
        } 
    e poi sotto c'è il form...

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.