Jump to content

[SOLVED] Header Problem - cant fix it


pcw

Recommended Posts

Hi,

 

I have read the post at the top of the page in regards to header errors, but still cannot fix it.

 

I got these three pages which all run as part of a larger script:

 

header.php

 

<?php 

function pageheader() {
print <<<HEADPAGE
<html>
<head>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
}
.style2 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
}
.style3 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}
{
.style4 {color: #FFFFFF}
.style6 {color: #FFFFFF; font-weight: bold; }
.style7 {color: #FFFFCC}
}

a:link {
color: #FFFF99;
}


-->
</style>

</head>
<body bgcolor="#14285f">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr bgcolor="02021e">
    <td height="58" nowrap="nowrap" colspan="3" id="logo" valign="bottom"><div align="center" class="style1">SiteBuilder Version 2.0 </div></td>
  </tr>
  <tr bgcolor="02021E">
    <td height="57" nowrap="nowrap" colspan="3" id="tagline" valign="top"><div align="center" class="style2">Build your own membership site </div></td>
  </tr>
</table>
<br>
HEADPAGE;
}
?>

 

login_chk.php

 

<?php

function login_chk() {
include("data/required.php");


session_start(); 
$_SESSION['valid'] = false; 
if (isset($_POST['submit']))
{

	mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error());
	mysql_select_db( $db) or die(mysql_error());
	$username = mysql_real_escape_string($_POST['username']);
	$password_encoded = mysql_real_escape_string(base64_encode($_POST['password']));
	if ($result = mysql_query("SELECT username, password, verified FROM profiles WHERE username='$username' AND password='$password_encoded' AND verified='yes'"))
	{
		if (mysql_num_rows($result) > 0)
		{
				$_SESSION['valid'] = true; 
			header( 'Location: templates/members/loggedin.php' ) ; # Change this file to the page of your choice

					}else {
			echo "Login not successful.";
			login();
		}
	}else{
		echo "SQL Error: " . mysql_error();
	}
}
}

?>

 

and

 

loggedin.php

 

<?php
include_once("../common/header.php");
include_once("../common/footer.php");
session_start(); 
pageheader();

if($_SESSION['valid'] == true)
{

print '

<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
   <tr>
     <td> </td>
     <td> </td>
     <td> </td>
   </tr>
   <tr>
     <td valign="top">


      <table width="300" border="1" cellpadding="0" cellspacing="0">
       <tr>
         <td width="5" height="5"></td>
         <td></td>
         <td width="5"></td>
       </tr>
       <tr>
         <td></td>
         <td><table width="90%" border="0" cellpadding="0" cellspacing="0">
             <tr>
               <td colspan="2"><h2 class=style2>Members Area<br />
                 </h2>
                   <hr /></td>
             </tr>
             <tr><td class=style3>Your login has been successful</td></tr>

             <tr></tr>
           </table>
             <br />        </td>
         <td></td>
       </tr>
       <tr>
         <td height="5"></td>
         <td></td>
         <td></td>
       </tr>
     </table>

      </form>

       <br />
       <table width="300" border="1" cellpadding="0" cellspacing="0">
       <tr>
         <td width="5" height="5" ></td>
         <td> </td>
         <td width="5"></td>
       </tr>
       <tr>
         <td></td>
         <td><table width="90%" border="0" cellpadding="5" cellspacing="0">
             <tr>
               <td class=style3>Visit another secure page. </td>
             </tr>
             <tr>
               <td><h2><a href="./loggedin2.php">Go to page 2</a></h2></td>
             </tr>
           </table>
          </td>
         <td></td>
       </tr>
       <tr>
         <td height="5"></td>
         <td></td>
         <td></td>
       </tr>
     </table>
     <p></p></td>
     <td width="20"> </td>
     <td valign="top"><br />
         <br />
         <h2 align="left" class=style2>Sitebuilder registration page </h2>
         <p align="justify" class=style3>
		You have successfully registered. If you wish to logout,<a href="logout.php">click here</a></p>
     <p align="justify" class=style3>You are free to modify this page as you wish.</p>
     <p align="justify" class=style3>Please follow the instruction guide, when altering the code. </p>
     </td>
   </tr>
</table>
</body>
</html>';
pagefooter();
} else {
			print "<META http-equiv='refresh' content='3;URL=login.php'>";

}
?>

 

but i get this error

 

Warning: Cannot modify header information - headers already sent by (output started at /home/moveitho/public_html/sitebuilder/templates/common/header.php:49) in /home/moveitho/public_html/sitebuilder/data/library/login_chk.php on line 21

 

I have tried moving the session() and header functions but cant seem to fix it.

 

Please help! 

 

Thanks

Link to comment
Share on other sites

The "session_start()" MUST be executed before any output is sent to the screen. In your case,

<?php
include_once("../common/header.php");
?>

is sending output, so move "session_start()" to before the include.

<?php
session_start();
include_once("../common/header.php");
include_once("../common/footer.php");
?>

 

Ken

Link to comment
Share on other sites

Hi guys,

 

thanks for your reply, I tried this and still get this error

 

Warning: Cannot modify header information - headers already sent by (output started at /home/moveitho/public_html/sitebuilder/templates/common/header.php:49) in /home/moveitho/public_html/sitebuilder/data/library/login_chk.php on line 21

 

 

Link to comment
Share on other sites

Please READ the error message -

 

output started at /home/moveitho/public_html/sitebuilder/templates/common/header.php:49

 

If that is the whole header.php file that you posted, then in your actual file, you have something, like a new-line, after the closing ?> tag.

Link to comment
Share on other sites

Hi guys, thanks again, tried both but neither worked.

 

There are no lines after ?> in the header.php file

 

The ob_start(); and ob_end_flush(); made no difference.

 

I am thinking the prob is on the login_chk.php page with this line

 

header( 'Location: templates/members/loggedin.php' ) ;

 

But dont know what to do to fix it :(

 

 

Link to comment
Share on other sites

Hi guys, thanks again, tried both but neither worked.

 

There are no lines after ?> in the header.php file

 

The ob_start(); and ob_end_flush(); made no difference.

 

I am thinking the prob is on the login_chk.php page with this line

 

header( 'Location: templates/members/loggedin.php' ) ;

 

But dont know what to do to fix it :(

 

 

where did you place the opening and closing ob lines?

 

the ob_start(); is to be placed before any header() functions, or anything that is being outputted/parsed to the browser .. and the ob_end_flush(); is to be placed after you have written in all your HTML, header() functions, etc...

 

i keep my ob_start(); at the top of my head file and ob_end_flush(); at the bottom of my footer file.

 

what is in the "data/required.php" file?

Link to comment
Share on other sites

I have put them like this

 

header.php

 

<?php 
ob_start(); 
function pageheader() {
print <<<HEADPAGE
<html>
<head>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
}
.style2 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
}
.style3 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}
{
.style4 {color: #FFFFFF}
.style6 {color: #FFFFFF; font-weight: bold; }
.style7 {color: #FFFFCC}
}

a:link {
color: #FFFF99;
}
-->
</style>

</head>
<body bgcolor="#14285f">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr bgcolor="02021e">
    <td height="58" nowrap="nowrap" colspan="3" id="logo" valign="bottom"><div align="center" class="style1">SiteBuilder Version 2.0 </div></td>
  </tr>
  <tr bgcolor="02021E">
    <td height="57" nowrap="nowrap" colspan="3" id="tagline" valign="top"><div align="center" class="style2">Build your own membership site </div></td>
  </tr>
</table>
<br>
HEADPAGE;
}
?>

 

loggedin.php

 

<?php
session_start(); 
if($_SESSION['valid'] == true)
{
include_once("../common/header.php");
include_once("../common/footer.php");
pageheader();



print '

<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
   <tr>
     <td> </td>
     <td> </td>
     <td> </td>
   </tr>
   <tr>
     <td valign="top">


      <table width="300" border="1" cellpadding="0" cellspacing="0">
       <tr>
         <td width="5" height="5"></td>
         <td></td>
         <td width="5"></td>
       </tr>
       <tr>
         <td></td>
         <td><table width="90%" border="0" cellpadding="0" cellspacing="0">
             <tr>
               <td colspan="2"><h2 class=style2>Members Area<br />
                 </h2>
                   <hr /></td>
             </tr>
             <tr><td class=style3>Your login has been successful</td></tr>

             <tr></tr>
           </table>
             <br />        </td>
         <td></td>
       </tr>
       <tr>
         <td height="5"></td>
         <td></td>
         <td></td>
       </tr>
     </table>

      </form>

       <br />
       <table width="300" border="1" cellpadding="0" cellspacing="0">
       <tr>
         <td width="5" height="5" ></td>
         <td> </td>
         <td width="5"></td>
       </tr>
       <tr>
         <td></td>
         <td><table width="90%" border="0" cellpadding="5" cellspacing="0">
             <tr>
               <td class=style3>Visit another secure page. </td>
             </tr>
             <tr>
               <td><h2><a href="./loggedin2.php">Go to page 2</a></h2></td>
             </tr>
           </table>
          </td>
         <td></td>
       </tr>
       <tr>
         <td height="5"></td>
         <td></td>
         <td></td>
       </tr>
     </table>
     <p></p></td>
     <td width="20"> </td>
     <td valign="top"><br />
         <br />
         <h2 align="left" class=style2>Sitebuilder registration page </h2>
         <p align="justify" class=style3>
		You have successfully registered. If you wish to logout,<a href="logout.php">click here</a></p>
     <p align="justify" class=style3>You are free to modify this page as you wish.</p>
     <p align="justify" class=style3>Please follow the instruction guide, when altering the code. </p>
     </td>
   </tr>
</table>
</body>
</html>';
pagefooter();
} else {
			print "<META http-equiv='refresh' content='3;URL=login.php'>";

}
ob_end_flush();
?>

 

login_chk.php

 

<?php

function login_chk() {
include("data/required.php");


session_start(); 
$_SESSION['valid'] = false; 
if (isset($_POST['submit']))
{

	mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error());
	mysql_select_db( $db) or die(mysql_error());
	$username = mysql_real_escape_string($_POST['username']);
	$password_encoded = mysql_real_escape_string(base64_encode($_POST['password']));
	if ($result = mysql_query("SELECT username, password, verified FROM profiles WHERE username='$username' AND password='$password_encoded' AND verified='yes'"))
	{
		if (mysql_num_rows($result) > 0)
		{
				$_SESSION['valid'] = true; 
			header( 'Location: templates/members/loggedin.php' ) ; # Change this file to the page of your choice

					}else {
			echo "Login not successful.";
			login();
		}
	}else{
		echo "SQL Error: " . mysql_error();
	}
}
}
?>

Link to comment
Share on other sites

instead of including the header file and then calling the function within it which is essentially not much of functioning function at all, why don't you just include the scripts where they are needed, ie.

 

include_once (header.php);

//stuff

include_once (footer.php);

 

instead of including them and then calling the content at different places, just makes things more confusing.

 

i'm just finding it very difficult to follow your code.

Link to comment
Share on other sites

The current error is due to the header() redirect in login_chk.php/login_chk() function and whatever is being output at the end of the header.php file (assuming the error message is accurate.)

 

The posted code does not contain any reference to login_chk.php/login_chk(). Where is that file being included and the function called from?

Link to comment
Share on other sites

Ok, I moved session_start() but no luck.

 

PFMaBiSmAd:

 

This is the code for login.php which refers to another file sb.php?cmd=logchk which just contains the function login_chk();

 

<?
include_once("../common/header.php");
print '<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td valign="top">
<form action="../../sb.php?cmd=logchk" method="post">
<input type="hidden" name="action" value="login">
<table width="300" border="1" cellpadding="0" cellspacing="0">
<tr><td width="5" height="5"></td>
<td>
<table width="90%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<center><h2 class="style7">Log On<br /></h2></center><hr /></td>
</tr>
<tr>
<td align="right"><span class="style3">Username:</span></td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td align="right"><span class="style3">Password:</span></td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></td>
</tr>
<tr>
</table>
</td>
</tr>
</table>
</form>
<br />
<table width="300" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="90%" border="0" cellpadding="5" cellspacing="0"><tr><td><center><h2 class="style7">Not a member? </h2></center></td>
</tr>
<tr>
<td><center><h2><a href="./sb.php">Join Up </a></h><center></td>
</tr>
</table>
</td>
</tr>
</table></td>
<td valign="top"><br /><br /><h2 align="left" class="style7">Sitebuilder login page </h2>
<p align="justify" class="style3">Thank you for registering. Please login to access the members area.</p>
<p align="justify" class="style3">You are free to modify this page as you wish.</p>
<p align="justify" class="style3">Please follow the instruction guide, when altering the code. </p>     </td></tr></table>';
include_once("../common/footer.php");

?>

Link to comment
Share on other sites

  • 2 weeks later...

my website was running fine but now i am having the problem shows

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/n/e/l/nelgo1/html/xxx/secure/nsa/submenucontents.php:3) in /home/content/n/e/l/nelgo1/html/xxx/secure/nsa/submenucontents.php on line 22

 

where in line no 22 i see

 

header("Location: http://www.xxx.com/xxx/xxx.php");

 

but now i fixed the problem using

 

ob_start();

 

and

 

ob_end_flush();

 

but dont know what happened,why it happens? can any ione please specify the answer

 

 

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.