Cobby Posted August 25, 2007 Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/ Share on other sites More sharing options...
teng84 Posted August 25, 2007 Share Posted August 25, 2007 session_start(); this should be declared at the top most of the page or add ob_start() at the top Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333709 Share on other sites More sharing options...
Cobby Posted August 25, 2007 Author Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333710 Share on other sites More sharing options...
corbin Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333711 Share on other sites More sharing options...
Cobby Posted August 25, 2007 Author Share Posted August 25, 2007 Just did a little experiment, I replace include 'configs/config.php'; with the actual contents of config.php and it work??? Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333712 Share on other sites More sharing options...
Cobby Posted August 25, 2007 Author Share Posted August 25, 2007 Basically that means something is being output in config.php on line 15, and it can't send headers after that. But thats the thing, line 15 is the ?> end tag. Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333713 Share on other sites More sharing options...
Cobby Posted August 25, 2007 Author Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333719 Share on other sites More sharing options...
vijayfreaks Posted August 25, 2007 Share Posted August 25, 2007 Hi.. try to remove blank line and then check.. -Vijay Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333722 Share on other sites More sharing options...
Cobby Posted August 25, 2007 Author Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333724 Share on other sites More sharing options...
Sesquipedalian Posted August 25, 2007 Share Posted August 25, 2007 It's because header(); has to be set at the beginning of the document (or if not at the beginning before anything else is actually done). So like this wouldn't work: echo 'Hello World'; if (1=1) { header('page.php'); } but this might? if (1=1) { header('page.php'); } echo 'Hello World'; Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333740 Share on other sites More sharing options...
dbo Posted August 25, 2007 Share Posted August 25, 2007 I've seen this problem occur when there are newlines at the end of an include file... after the ?> tag. Quote Link to comment https://forums.phpfreaks.com/topic/66604-solved-says-header-info-has-been-ssent-but-it-hasnt/#findComment-333951 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.