hey,
i have been working on a project over the summer.. and it works fine and dandy on the PHP installation i used when creating it (php 4.3.6) using mac os server 10.3.5
but when i moved it onto sourceforge i find that when i try to login to my program (it is a content management type thing,) i get an annoying headers cannot be sent problem. i already know that that usually means there is an echo or print somewhere before the Header() is called. but the thing is, my login() function is sandwiched between two other function calls which are for the HTML header and footer for the site.
i don't understand why i am getting headers cannot be sent errors on this, but apparently not on the PHP installation i am using on the server i worked on. sourceforge is using php 4.1.2, so i wonder if this is a version problem. and then i read about output buffering, but i don't know how to use it effectively, as my attempts at using haven't fixed my problem. the code is made up of a few files, and i can't post it all here, because that would take up too much space, i think. but here are the errors:
Warning: Cannot add header information - headers already sent by (output started at /home/groups/m/mi/mi-/htdocs/themes/default/default.theme:26) in /home/groups/m/mi/mi-/htdocs/admin/admin.php on line 728
and here are some function snippets:
file: admin.php
///////////////////////////////////////////////////////////////////
// login()
// Input: nothing
// Returns: nothing
// Output: Shows login panel.
function login() {
// If login form has been sent
if (isset($_POST["submit"])) {
// If user and password fields have been filled out
if ((isset($_POST["user"])) && (isset($_POST["pass"]))) {
// DB connect
$db = new qiDB();
$query = "select * from users where u_name='$_POST[user]'";
$db->query($query);
// If there is a user found with the inputted username
if (mysql_num_rows($db->query($query)) > 0) {
while($db->next_record()):
// Check to see if the inputted password matches the password
// for that specific username in database
if ($db->Record["u_pass"] == md5($_POST["pass"])) {
// Put user information into a cookie
$user = $_POST["user"];
$pass = $_POST["pass"];
$permission = $db->Record["u_permission"];
$uid = $db->Record["u_id"];
$directory_location = $db->Record["u_directory_start"];
// Find out where to direct to
if ($directory_location == "") {
$directory_location = "Location: admin.php";
} else {
$directory_location = "Location: admin.php?go=" . $directory_location;
}
$user_info = base64_encode("$user:$pass:$permission:$uid");
setcookie("user", "$user_info", time()+7200, "/");
Header($directory_location);
// Else, if password doesn't match
} else {
$_SESSION["error_messages"] = "Invalid password.";
Header("Location: admin.php");
}
endwhile;
} else {
// Else, if no username exists from inputted username
$_SESSION["error_messages"] = "Invalid username.";
Header("Location: admin.php");
}
}
} else {
theme_header();
echo <<<HTML
<table border="0">
<form method="post" action="admin.php?go=login">
<tr><td>Username: </td><td><input type="text" name="user" size=10></td></tr>
<tr><td>Password: </td><td><input type="password" name="pass" size=10></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="login"></td></tr>
</form>
</table>
HTML;
// If there are any error messages show them, then clear the $error_messages variable
if (isset($_SESSION["error_messages"])) {
echo $_SESSION["error_messages"];
unset($_SESSION["error_messages"]);
}
}
theme_footer();
}
file: default.theme
////////////////////////////////////////////////////////////////
// theme_header()
//
function theme_header() {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>
<?php
// database call
$db = new qiDB();
$query = "select * from core_preferences";
$db->query($query);
while($db->next_record()):
$site_title = $db->Record["site_title"];
$top_level = $db->Record["top_level"];
endwhile;
echo $site_title;
?>
</title>
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $top_level ?>/themes/default/default.css" title="en" />
</head>
<body>
<div id="main_box">
<div id="banner">
<a href="<?php echo $top_level; ?>"><h1><?php echo $site_title ?></h1></a>
</div>
<div id="search">
<form action="<?php echo $top_level ?>/modules.php?mod=search" method="post">
<input class="smInput" type="text" name="keyword" size="15">
<input class="smInput" type="submit" name="submit" value="Search">
</form>
</div>
<div id="sub_banner">
<?php
// database call
$db = new qiDB();
$query = "select * from categories";
$db->query($query);
while($db->next_record()):
echo "<a href=\"$top_level/modules.php?mod=story&cat=". $db->Record["c_id"] . "\">" . ucfirst($db->Record["c_title"]) . "</a> ";
endwhile;
?>
</div>
<div id="content">
<?php
} // end theme_header function
////////////////////////////////////////////////////////////////
// theme_footer()
//
function theme_footer() {
?>
</div>
<div id="footer">
<?php
// database call
$db = new qiDB();
$query = "select * from core_preferences";
$db->query($query);
while($db->next_record()):
echo $db->Record["footer"];
endwhile;
?>
<br /><br /><br />
</div>
</body>
</html>
<?php
} // end theme_footer function
thanks for any suggestions