Hi please help to get rid of this error/warning...
Please see the following code carefully..
Look at the errors first
-------------------------------------------
Warning: Cannot modify header information - headers already sent by (output started at /home/compkcom/public_html/includes/config.php:1) in /home/compkcom/public_html/cmpanel/check_login.php on line 20

-------------------------------------------
here goes the php script
---------------

<?php
session_start();
?>
<?php
if((isset($_POST['username'])&&$_POST['username']!="")&&(isset($_POST['password'])&&$_POST['password']!="")){
	$error='';	
	require('../includes/config.php');
	$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die('Could not connect to MySQL database. ' . mysql_error());
	mysql_select_db(SQL_DB,$conn);
	$query = "SELECT COUNT(username) AS record FROM admin WHERE username ='" . $_POST['username']."' AND password = '".$_POST['password']."'";
	$result = mysql_query($query);
	$row = mysql_fetch_array($result);
	if($row['record']==1){
		$_SESSION['user_logged'] = $_POST['username'];
		$_SESSION['user_password'] = $_POST['password'];
		header("location:welcome.php");
	}
	else{
		$error .="Please+Enter+Correct+Username+and+password%21%0D%0A";
		header("location:index.php?&error=".$error);
	}
}
else{
		$error .="Please+Enter+the+Username+and+password+First%21%0D%0A";
		header("location:index.php?&error=".$error);
}
?>

----------------
This script is working fine on my local window server, but on my linux hosted server it is giving warning..
Warning is coming because because of inclusion of require('../includes/config.php');
but inclusion of this file is necessary, please help to solve this issue..
or Suggest some alternatives
Thanks..
God bless you..

Hi....

try to check this below code...

<?php
ob_start();
session_start();

if((isset($_POST['username'])&&$_POST['username']!="")&&(isset($_POST['password'])&&$_POST['password']!="")){
	$error='';	
	require_once('../includes/config.php');
	$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die('Could not connect to MySQL database. ' . mysql_error());
	mysql_select_db(SQL_DB,$conn);
	$query = "SELECT COUNT(username) AS record FROM admin WHERE username ='" . $_POST['username']."' AND password = '".$_POST['password']."'";
	$result = mysql_query($query);
	$row = mysql_fetch_array($result);
	if($row['record']==1){
		$_SESSION['user_logged'] = $_POST['username'];
		$_SESSION['user_password'] = $_POST['password'];
		header("location:welcome.php");
	}
	else{
		$error .="Please+Enter+Correct+Username+and+password%21%0D%0A";
		header("location:index.php?error=".$error."");
	}
}
else{
		$error .="Please+Enter+the+Username+and+password+First%21%0D%0A";
		header("location:index.php?error=".$error);
}
?>

The problem is not in the check_login.php file. The error is in your config.php file.

You can NOT have ANY output from php prior to calling the header function. I assume you have something like the following in your config.php file:

<?php
//Ignore the next line, it just reproduces your error.
header('location: http://www.google.com');

notice that there is a space before the <?php tag.
This is the error message it produces:

Warning: Cannot modify header information - headers already sent by (output started at ****\headerCheck.php:1) in ****\headerCheck.php on line 2

Dear Sir,
Fist of all thank you very much for replying..
Please look at the code of config.php
-------------------------------------

<?php define('SQL_HOST','localhost');define('SQL_USER','compcom_care');define('SQL_PASS','ptk');define('SQL_DB','compcom_ccc');?>

-------------------------------------

Download the attached file and try it. All i did was copy the code from your posting into it and I noticed a weird unicode glitch i've seen before. When I saved the file correcting for it, the glitch went away, it might be the problem you're having.

Attachments
<?php define('SQL_HOST','localhost');define('SQL_USER','compcom_care');define('SQL_PASS','ptk');define('SQL_DB','compcom_ccc');?>
This article has been dead for over six months. Start a new discussion instead.