Carbos
Carbos

Reputation: 117

Redirect in the same page doesnt work?

i have this code:

// index.php
if(!isset($_SESSION['user']) && !isset($_SESSION['id']){    
     // My Code 
     if($ris1['pass'] == $pass)){ // it controls if the pass the user inserts is true...
         $_SESSION['user'] = $ris1['user'];
         $_SESSION['id'] = $ris1['id'];
         die(header("Location: index.php")); // the same page 
     }
} else { 
     // My Code 
}

I insert : die(header("Location: index.php")); for redirect automatically the page, but it if the pass is correct, it saves my Session, but, when i redirect the user, the user sees half of the same page you see if the $_SESSION is not define but the $_SESSION is isset, and i for see what i have in the else (in my code) i must update the page... I try use ob_start() , but it doesn't work... Why the my page doesn't redirect automatically and go , in the else?

Upvotes: 0

Views: 69

Answers (1)

soyuka
soyuka

Reputation: 9105

Try to redirect before aborting the current code :

if(!isset($_SESSION['user']) && !isset($_SESSION['id'])) {    
     // My Code 
     if($ris1['pass'] == $pass)){ // it controls if the pass the user inserts is true...
         $_SESSION['user'] = $ris1['user'];
         $_SESSION['id'] = $ris1['id'];
         header("Location: index.php"); // the same page 
         die();
     }
} else { 
     // My Code 
}

Upvotes: 1

Related Questions