Jump to content

[SOLVED] says header info has been ssent, but it hasn't!


Cobby

Recommended Posts

Hello,

 

I have a problem, it says header information has been sent by my config.php file, which just stores some variables.

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\user\admin\configs\config.php:15) in C:\wamp\www\user\admin\login.php on line 44

 

config.php

<?php


$server = "localhost";
$db_user = "root";
$db_pass = "no";  //not my real password, intentionally change for the this topic
$db_name = "no";  //not real db, see above comment

$link = mysql_connect($server, $db_user, $db_pass, $db_name);
$select = mysql_select_db($db_name, $link);

require_once("C:/wamp/www/user/admin/smarty/libs/Smarty.class.php");
$smarty = new Smarty;

?> 

 

login.php

<?php

function login($username, $password, $link){
if (empty($username) && empty($password)){
	$error = "Some fields are empty.";
	return $error;
}else{
	$sql = "SELECT * 
		FROM `jc_users` 
		WHERE `username` = '".mysql_escape_string($username)."' 
		AND `password` = '".mysql_escape_string($password)."'";

	$query = mysql_query($sql, $link);

	if(mysql_num_rows($query) == 1){
		return 'true';
	}else{
		$error = "You have supplied an invalid username or password.";
		return $error;
	}	
}	
}

session_start();

include 'configs/config.php';

if(isset($_SESSION['authenticated']) && $_SESSION['authenticated'] == true){
	header("Location: http://localhost/JC Epidemic/admin//index.php");
}else{	
if(isset($_POST['submit'])){

	$login = login($_POST['username'], $_POST['password'], $link);
	if($login == true){
		header("Location: http://localhost/JC Epidemic/admin/index.php");
	}else{
		$smarty->assign("error", login($_POST['username'], $_POST['password'], $link));
		$smarty->assign("title", "Event Management System - Error!");
		$smarty->display("overall_header.tpl.html");
		$smarty->display("loginform.tpl.html");
		$smarty->display("overall_footer.tpl.html");		
	}

}else{
	$smarty->assign("title", "Event Management System");
	$smarty->display("overall_header.tpl.html");
	$smarty->display("loginform.tpl.html");
	$smarty->display("overall_footer.tpl.html");	
}
}	



?>

 

Can someone tell me where the header info is been sent?

 

Cheers,

Cobby

Link to comment
Share on other sites

session_start(); this should be declared at the top most of the page or add ob_start() at the top

 

Thanks for that, but login hasn't been finished yet, I am going to move the login() function when its all working to config.php.

Link to comment
Share on other sites

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\user\admin\configs\config.php:15) in C:\wamp\www\user\admin\login.php on line 44

 

That means that it's unable to send the headers requested to be sent on line 44 of login.php because, data has already been sent by line 15 of config.php.

 

Basically that means something is being output in config.php on line 15, and it can't send headers after that.

Link to comment
Share on other sites

Ok, this is freaking me out, I moved all the data from config.php for it was just left with <?php ?> (just one line) and that still return the header sent error!

 

But if I remove the php open/close tags everything goes normal.

Link to comment
Share on other sites

Ok, I didn't solve the problem...but I found a solution:

 

<?php

function redirect($delay, $url){
echo "<meta content=\"".$delay."; URL=".$url."\" http-equiv=\"Refresh\" />";
}

?>

Hope that helps someone in the future, redirects regardless of headers 

Cheers,
Cobby

Link to comment
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.