virtuexru Posted March 8, 2007 Share Posted March 8, 2007 OK So I read the sticky, but I am still stuck.. any ideas? I'm logging in through index.php, before the header of index.php I have: <?php session_start(); if (isset($_POST['email']) && isset($_POST['password'])) { include('login.php'); } ?> This is my error: Warning: Cannot modify header information - headers already sent by (output started at /**/**/public_html/config/connect.php:6) in /**/**/public_html/login.php on line 36 Warning: Cannot modify header information - headers already sent by (output started at /**/**/public_html/config/connect.php:6) in /**/**/public_html/login.php on line 50 The connect.php is this: <?php $connect = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die("Unable to select database"); ?> and on the login.php is: setcookie ("member",$email,time()+172800,"/"); $member = $email; /* In-case cookies are turned off, set the session */ $_SESSION['member'] = true; /* Update login timer */ $qUpdate = "UPDATE xxx SET login = now() WHERE email='$email' AND password='$passwordencrypt' AND status='Y' "; $rsUpdate = mysql_query($qUpdate); if ($rsUpdate) { header("Location: profile.php"); } Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/ Share on other sites More sharing options...
Daniel0 Posted March 8, 2007 Share Posted March 8, 2007 You might want to put ob_start() at the very top, and ob_end_flush() on the bottom. That way, when you echo/print, it doesn't actually do it, but rather buffers it and then eventually do it at the end of script execution. Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202121 Share on other sites More sharing options...
suzzane2020 Posted March 8, 2007 Share Posted March 8, 2007 in connect.php (any of the files having header or session info) there should not be any space before the coding. Nothin shud be sent to te server before the header info. so trim any spac between <? and the code Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202122 Share on other sites More sharing options...
virtuexru Posted March 8, 2007 Author Share Posted March 8, 2007 Niether of those worked, still same error :|. Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202129 Share on other sites More sharing options...
suzzane2020 Posted March 8, 2007 Share Posted March 8, 2007 cud u post the lines where u get the error? Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202131 Share on other sites More sharing options...
virtuexru Posted March 8, 2007 Author Share Posted March 8, 2007 Warning: Cannot modify header information - headers already sent by (output started at /home2/virtuex7/public_html/config/connect.php:4) in /home2/virtuex7/public_html/login.php on line 33 Warning: Cannot modify header information - headers already sent by (output started at /home2/virtuex7/public_html/config/connect.php:4) in /home2/virtuex7/public_html/login.php on line 47 LINE 33: setcookie ("member",$email,time()+172800,"/"); LINE 47: header("Location: profile.php"); Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202133 Share on other sites More sharing options...
suzzane2020 Posted March 8, 2007 Share Posted March 8, 2007 headers usually need to be placed before the html.. but in this case u cud try this : print("<script>document.location.href='dd.php'</script>"); instead of header Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202135 Share on other sites More sharing options...
suzzane2020 Posted March 8, 2007 Share Posted March 8, 2007 correction..plz use ur filename in place of dd.php Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202138 Share on other sites More sharing options...
virtuexru Posted March 8, 2007 Author Share Posted March 8, 2007 That works but I still get the first error from the setcookie line 33. Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202140 Share on other sites More sharing options...
suzzane2020 Posted March 8, 2007 Share Posted March 8, 2007 so thts definitly with the connect.php make sure there are no spaces at all between the <?php and the code and the <?php tag shud start from te very beginin of the file eg: <?php mysql_select_db() ?> Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202145 Share on other sites More sharing options...
virtuexru Posted March 8, 2007 Author Share Posted March 8, 2007 Here's the connect.php file: <?php $connect = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die("Unable to select database"); ?> Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202149 Share on other sites More sharing options...
virtuexru Posted March 8, 2007 Author Share Posted March 8, 2007 Bump?! Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202166 Share on other sites More sharing options...
neo777ph Posted March 8, 2007 Share Posted March 8, 2007 ob_start(); // declare on every page at the first line before the tags <META> or <HTML>.. this would cache headers informations.. So redirection would be possible.. I had the same problem with yours,,But as the forum had implied..Use "best practice" meaning code first before HTML.. Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202223 Share on other sites More sharing options...
virtuexru Posted March 8, 2007 Author Share Posted March 8, 2007 Worked neo! I put it on top of the index, login and connect pages. Everything is perfect now, thank you. Link to comment https://forums.phpfreaks.com/topic/41699-solved-header-issue-i-know-i-know/#findComment-202610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.