Confused about how and when to use header() to redirect to different page?

Mr.7aMaD

New Member
I had been using the header() a lot in my application to redirect to different pages, have a look at my code below.i have put the code in top of the page and i haven't used any comments \[code\]if(isset($_SESSION['loggedin'])){header("Location: dashboard.php");exit;}else {require_once('models/validation.php');require_once('config/database.php'); \[/code\]and below on line 50 i have put on some codes to check the login credentials and redirect it to dashboard.php\[code\]if( !empty($_POST['username']) || !empty($_POST['password'])) {if( check_login($_POST['username'], $_POST['password'])) { header("Location: dashboard.php"); exit; \[/code\]the first set of code works fine because when i login and try to access the index.php the first set of code come into action and push me back to dashboard.phpi am facing the problem with the second set of code below when i login successfully it does not redirect me to dashboard.php instead it gives me the following error\[quote\] Warning: Cannot modify header information - headers already sent by (output started at /home/bhatkaln/public_html/test/admin-login/index.php:17) in /home/bhatkaln/public_html/test/admin-login/index.php on line 54\[/quote\]where i am going wrong? is it fine to use header() for redirecting or i should consider using alternative \[code\]<meta http-equiv="refresh" content="0;dashboard.php"/>";\[/code\]Edit : Sorry Guys i updated my error code and here is my line 53, 54 and 55. \[code\]if( check_login($_POST['username'], $_POST['password'])) { header("Location: dashboard.php"); exit;\[/code\]
 
Back
Top