kumarrana Posted July 7, 2008 Share Posted July 7, 2008 I am well aware of the error I have been getting but I just can't fix it. Error is Warning: Cannot modify header information - headers already sent by (output started at ..................index.php:18) in ........................login.php on line 28.Can anybody find bugs on it here is the login.php file included on index.php page <?php require_once('mysql_login.php'); session_start(); $errorMessage = ''; if(isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { // check if the username and password combination is correct $userpass = md5($_POST['txtPassword']); $username = $_POST['txtUserId']; $result = mysql_query("SELECT * FROM user WHERE password='$userpass' AND username='$username'") or die("Couldn't query the user-database."); $row_user = mysql_fetch_array($result); $num = mysql_result($result, 0); if(!$num) { $errorMessage = 'Sorry, wrong username / password'; } else { $_SESSION['autheticate'] = true; $_SESSION['identification'] = $row_user['identification']; $_SESSION['admin'] = $row_user['admin']; // after login we move to the main page header('Location: ../index.php'); exit; } } ?> and my index page look like this <?php session_start(); if(isset($_SESSION['autheticate'])) { $identification = $_SESSION['identification']; $admin = $_SESSION['admin']; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Title</title> <link rel="stylesheet" href="includes/style.css" type="text/css" /></head> <body> <?php include("header.htm"); echo "<div class = \" verticalmenu \" >"; if(!isset($_SESSION['autheticate'])) { include("includes/login.php"); //echo "<a href = includes/logout.php> Logout </a>"; } else { include("includes/logout.php"); } echo "</div>"; ?> </body> </html> Can anybody tell me what am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/113655-error-after-header/ Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 I beg of you to read the stickied post on this board. Quote Link to comment https://forums.phpfreaks.com/topic/113655-error-after-header/#findComment-584073 Share on other sites More sharing options...
kumarrana Posted July 8, 2008 Author Share Posted July 8, 2008 What do you mean by stickied post? Can you give the link Quote Link to comment https://forums.phpfreaks.com/topic/113655-error-after-header/#findComment-584298 Share on other sites More sharing options...
trq Posted July 8, 2008 Share Posted July 8, 2008 What do you mean by stickied post? Can you give the link The big post at the top of this forum that reads HEADER ERRORS..... Quote Link to comment https://forums.phpfreaks.com/topic/113655-error-after-header/#findComment-584307 Share on other sites More sharing options...
kumarrana Posted July 9, 2008 Author Share Posted July 9, 2008 Even knowing that, I could not avoid the header problem. Instead I used echo "<meta http-equiv = \"refresh\" content = \"1; URL=test.php\">"; Can that be alternative solution? In past I had problem setting session once page is refreshed which I could not debug. I have login.php page included on index.php page. login.php will only appear if session is not set. My login.php page resides in <div></div>. Please somebody help me to get out this pain. btw I tried flush() Quote Link to comment https://forums.phpfreaks.com/topic/113655-error-after-header/#findComment-585137 Share on other sites More sharing options...
trq Posted July 9, 2008 Share Posted July 9, 2008 Its simply a matter of organising your code in such a way that nothing is sent to the browser prior to calling header(). Quote Link to comment https://forums.phpfreaks.com/topic/113655-error-after-header/#findComment-585165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.