Forum Moderators: coopster
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\FYP\admin\admin_controls.php:4) in C:\Program Files\Apache Group\Apache2\htdocs\FYP\admin\logout.php on line 4
I've read up on this error and it seems that it was caused by excess blanks or lines in the file. I can't seem to find my blank or space.
In my case it would be at admin_controls.php right?
Here is a little portion of the script in question
<html>
<head>
<title>Staff Control Panel</title>
<style type="text/css" media="all">@import "style.css";</style>
</head>
<body>
<div id="Navigation">
<h2>Control Panel</h2>
<?php
$page = $_GET['page'];
$login=false;
$admin=false;
if(isset($_COOKIE["username"]) && isset($_COOKIE["password"]))
{
$login=true;
echo"
[ <a href=\"admin_controls.php?page=addCat\">Add Category</a> ] [ <a href=\"admin_controls.php?page=editCat\">Edit Category</a> ] [ <a href=\"admin_controls.php?page=removeCat\">Remove Category</a> ]<br>
[ <a href=\"admin_controls.php?page=addPro\">Add Product</a> ] [<a href=\"admin_controls.php?page=editPro\"> Edit Product</a> ] [ <a href=\"admin_controls.php?page=removePro\">Remove Product</a> ]";
include("../t_opendb.php");
And the error was because I wanna trigger a logout script...
setcookie("username", $_COOKIE["username"], time()-3600);//make cookie invalid
setcookie("password", $_COOKIE["password"], time()-3600);//make cookie invalid
<?php
setcookie("username", $_COOKIE["username"], time()-3600);//make cookie invalid
setcookie("password", $_COOKIE["password"], time()-3600);//make cookie invalid
$header = "<META HTTP-EQUIV=\"refresh\" CONTENT=\"3; URL=index.html\">";
?>
<html>
<HEAD>
<TITLE>Rediredting...</TITLE>
<?php echo $header;?>
</HEAD>
I had HTML before and after checking cookies to display my navigations. Certain navigation will only appear if user is lodded in.
if(isset($_COOKIE["username"]) && isset($_COOKIE["password"]))
<?php
$page = $_GET['page'];
if(isset($_COOKIE["username"]) && isset($_COOKIE["password"]))
{
$login=true;
include("../t_opendb.php");
$sql = "SELECT access_rights FROM productcatalog_access WHERE access_uid = '".$_COOKIE["username"]."'";
$mysql_result=mysql_query($sql, $connection);
$num_rows=mysql_num_rows($mysql_result);
if($row=mysql_fetch_array($mysql_result))
{
$admin_rights = $row["access_rights"];
}
if($admin_rights > 0)
{
$admin=true;
}
}
else
{
$login=false;
$admin=false;
}
?>
<html>
<head>
<title>Staff Control Panel</title>
<style type="text/css" media="all">@import "style.css";</style>
</head>
<body>
<div id="Navigation">
<h2>Control Panel</h2>
<?php
if($login = true)
{
echo "[ <a href=\"admin_controls.php?page=addCat\">Add Category</a> ] [ <a href=\"admin_controls.php?page=editCat\">Edit Category</a> ] [ <a href=\"admin_controls.php?page=removeCat\">Remove Category</a> ]<br>[ <a href=\"admin_controls.php?page=addPro\">Add Product</a> ] [<a href=\"admin_controls.php?page=editPro\"> Edit Product</a> ] [ <a href=\"admin_controls.php?page=removePro\">Remove Product</a> ]";
if($admin = true)
{
echo "<br>[ <a href=\"admin_controls.php?page=addStaff\">Add Staff</a> ] [<a href=\"admin_controls.php?page=editStaff\"> Edit Staff</a> ] [ <a href=\"admin_controls.php?page=removeStaff\">Remove Staff</a> ]";
}
echo "<div align=right><font size=1><p><a href=\"admin_controls.php?page=logout\">Logout</a></font></div>";
}
echo "</div>";
echo "<div id=\"Content\">";
if (empty($page) && ($login=true))
{
echo "<strong>Welcome</strong><hr>";
echo "Welcome " . $_COOKIE["username"];
echo "<br>Click on the above links to start...";
}
if($login=true)
{
$display = $_GET['page'];
switch ($display)
{
case "addCat":
include("addCat.html");
break;
case "editCat":
include("editCat.php");
break;
case "removeCat":
include("removeCat.php");
break;
case "addPro":
include("addPro.php");
break;
case "editPro":
include("editPro.php");
break;
case "removePro":
include("removePro.php");
break;
case "process_cayegory":
include("process_category.php");
break;
case "logout":
include("logout.php");
break;
}
if($admin=true)
{
$display = $_GET['page'];
switch ($display)
{
case "addStaff":
include("addStaff.html");
break;
case "editStaff":
include("staff.php?page=edit");
break;
case "removeStaff":
include("removeStaff.php");
break;
case "process_users":
include("process_users.php");
break;
}
}
}
?>
</div>
</body>
</html>
Is there another method is use to check is cookie is set that won't give me the "cannot modify header" error? Or would it work if I store all my echo "Link"; into $link = "link"; and then call them again at the end of my script?
first of all checking if a cookie is set does not need to produce any output so checking a cookie should not be the problem at all. the problem is: you output something before you're setting / unsetting your cookies. that does not work.
posting the whole code even helps nothing. instead it makes it for other readers more complicated to think about your problem. post the first lines only and the whole error message with the according line number information. that would help.
and yes: using echo at the end (output at the end), might help, because you're outputting too early. output destroys the ability to send headers (set cookies) and produces the error.