I was told that you can't have any HTML output before a header statement, but when I changed my script so my header statements were before the HTML it would no longer work and then I changed it back to the way I had it and it worked. Should I do anything about this?
Here's my script, this is the page that my client is redirected to when they login.
You'll notice at the way bottom i have a header statement that redirects the viewer if the cookie is not found.
<?php
// Connects to your Database
mysql_connect("localhost", "XXXXXX", "XXXXXXX") or die(mysql_error());
mysql_select_db("XXXXX_XXXX") or die(mysql_error());
//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{ header("Location: home.php");
}
//otherwise they are shown the admin area
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#background {
position:absolute;
left:0px;
top:0px;
width:854px;
height:640px;
z-index:0;
background-image: url(images/background.jpg);
}
#clientform {
position:absolute;
left:691px;
top:534px;
width:117px;
height:54px;
z-index:2;
}
#navbg {
position:absolute;
left:607px;
top:199px;
width:228px;
height:440px;
z-index:1;
background-image: url(images/client_nav_bg.png);
}
#navigation {
position:absolute;
left:613px;
top:198px;
width:217px;
height:301px;
z-index:3;
}
body {
background-image: url(images/canvas.jpg);
}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
</head>
<body>
<?php
echo "Admin Area<p>";
echo "Your Content<p>";
echo "<a href=home.php>Logout</a>";
?>
<div id="background" onfocus="MM_preloadImages('images/background.jpg')"></div>
<div id="navbg"></div>
<div id="navigation">
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','217','height','301','src','flash/nav','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','flash/nav' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="217" height="301">
<param name="movie" value="flash/nav.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<embed src="flash/nav.swf" width="217" height="301" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>
</object>
</noscript></div>
</body>
</html>
<?php
}
}
}
else
//if the cookie does not exist, they are taken to the login screen
{
header("Location: home.php");
}
?>