Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/113655-error-after-header/
Share on other sites

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()

 

Link to comment
https://forums.phpfreaks.com/topic/113655-error-after-header/#findComment-585137
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.