unidox Posted July 18, 2007 Share Posted July 18, 2007 I am making a new cms where it is built into the site. But I keep getting this error: Warning: Cannot modify header information - headers already sent by (output started at *****:16) in *****inc/func.inc.php on line 10 Here is my index.php: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <!-- This is where the main body will go --> Testing <!-- This starts the admin panel --> <?php /* Login Panel */ if ($_REQUEST['adm'] == "login") { $page = "Login"; require_once ("inc/db.inc.php"); require_once ("inc/func.inc.php"); if ($_REQUEST['m']) { if ($_REQUEST['m'] == "1") { $loginpass = $_POST['login_pass']; $password = md5($loginpass); $loginname = $_POST['login_name']; $checkrows = mysql_query ("SELECT * FROM admin_users WHERE username='$loginname' && password='$password'") or die (mysql_error()); $rowcount = mysql_num_rows ($checkrows); if ($rowcount == "0") { showError("User/Login Error"); exit; } if ($rowcount != "0") { header ("Location: index.php?adm=home"); $time = date("h:i:a"); $date = date("m/d/Y"); $last_logged = $time . "\n(" . $date . ")"; $ip = getenv ("REMOTE_ADDR"); MYSQL_QUERY("UPDATE admin_users SET last_logged='$last_logged', cur_ip='$ip' WHERE username='$loginname'") or die (mysql_error()); while ($mysql=mysql_fetch_array($checkrows)) { setcookie("access", $mysql[access],time()+60*60*24*30); } setcookie ("uniqueid",$loginname,time()+60*60*24*30); exit; } } elseif ($_REQUEST['m'] == "2") { header ("Location: index.php?adm=login"); setcookie ("uniqueid"); setcookie ("access"); exit; } } else { if ($_COOKIE['uniqueid'] == "") { $checkfields = "login_name&login_pass"; $errors = "Enter a username&Enter a password!"; $titles = "Username:&Password:"; $fields = "login_name&login_pass"; $type = "text&password"; $size = "30&30"; $maxlength = "25&25"; getHeader(); createJSValid($checkfields,$errors); createForm($titles,$fields,$type,$size,$maxlength,'1','','','','1'); } else { showError("You are already logged in, <a href=\"" . $_SERVER['PHP_SELF'] . "?m=2\">logout?</a>"); } } } ?> </body> </html> Here is part of my inc/func.inc.php(lines 0 -50): <?php require_once 'config.inc.php'; $oncolour = "#BCD5FE"; $offcolour = "#FFFFFF"; $bdrcolour = "#F0F0F0"; $islogged = preg_match("/index.php?adm=login/", $_SERVER['PHP_SELF']); if ($islogged == "0") { if ($_COOKIE['uniqueid'] == "") { header ("Location: index.php?adm=home"); exit; } } if ((!$_REQUEST['method']) || (!$_COOKIE['uniqueid'])) { $access = $_COOKIE['access']; if (array_search($page,$levels)) { if ($access <= $levels[$page]) { // less than or equal to as the higher you go the less privileges you have echo $access . $levels[$page]; //showError('You do not have access to this page.'); exit; } } } $browser = 'An Unidentified Browser'; $viewer = getenv('HTTP_USER_AGENT'); if (preg_match( "/MSIE/i", "$viewer" ) ) { $browser = 'Internet Explorer'; } if (preg_match( "/Netscape/i", "$viewer" ) ) { $browser = 'Netscape'; } if (preg_match( "/Opera/i", "$viewer" ) ) { $browser = 'Opera'; } if (preg_match( "/Firefox/i", "$viewer" ) ) { $browser = 'Mozilla Firefox'; } Please help. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 18, 2007 Share Posted July 18, 2007 Cookies have to be set before ANY output in the script. cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. http://php.net/set_cookie Quote Link to comment Share on other sites More sharing options...
unidox Posted July 18, 2007 Author Share Posted July 18, 2007 I did that though Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 18, 2007 Share Posted July 18, 2007 No...you have all this output at the start of your index page. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <!-- This is where the main body will go --> Testing <!-- This starts the admin panel --> Quote Link to comment Share on other sites More sharing options...
unidox Posted July 18, 2007 Author Share Posted July 18, 2007 So are you saying, move all the php script on top of that? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 18, 2007 Share Posted July 18, 2007 I think calling ob_start() at the top of your script will get rid of the error and allow you to set the cookie, but I'm not sure if it is the best practice or not. http://php.net/ob_start Quote Link to comment Share on other sites More sharing options...
unidox Posted July 18, 2007 Author Share Posted July 18, 2007 I added that, but now I got: Parse error: syntax error, unexpected T_IF in /home/clansuni/public_html/index.php on line 23 Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 18, 2007 Share Posted July 18, 2007 Change your index.php code to this: <?php ob_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <!-- This is where the main body will go --> <!-- This starts the admin panel --> <?php /* Login Panel */ if ($_REQUEST['adm'] == "login") { $page = "Login"; require_once ("inc/db.inc.php"); require_once ("inc/func.inc.php"); if ($_REQUEST['m']) { if ($_REQUEST['m'] == "1") { $loginpass = $_POST['login_pass']; $password = md5($loginpass); $loginname = $_POST['login_name']; $checkrows = mysql_query ("SELECT * FROM admin_users WHERE username='$loginname' && password='$password'") or die (mysql_error()); $rowcount = mysql_num_rows ($checkrows); if ($rowcount == "0") { showError("User/Login Error"); exit; } if ($rowcount != "0") { header ("Location: index.php?adm=home"); $time = date("h:i:a"); $date = date("m/d/Y"); $last_logged = $time . "\n(" . $date . ")"; $ip = getenv ("REMOTE_ADDR"); MYSQL_QUERY("UPDATE admin_users SET last_logged='$last_logged', cur_ip='$ip' WHERE username='$loginname'") or die (mysql_error()); while ($mysql=mysql_fetch_array($checkrows)) { setcookie("access", $mysql[access],time()+60*60*24*30); } setcookie ("uniqueid",$loginname,time()+60*60*24*30); exit; } } elseif ($_REQUEST['m'] == "2") { header ("Location: index.php?adm=login"); setcookie ("uniqueid"); setcookie ("access"); exit; } } else { if ($_COOKIE['uniqueid'] == "") { $checkfields = "login_name&login_pass"; $errors = "Enter a username&Enter a password!"; $titles = "Username:&Password:"; $fields = "login_name&login_pass"; $type = "text&password"; $size = "30&30"; $maxlength = "25&25"; getHeader(); createJSValid($checkfields,$errors); createForm($titles,$fields,$type,$size,$maxlength,'1','','','','1'); } else { showError("You are already logged in, <a href=\"" . $_SERVER['PHP_SELF'] . "?m=2\">logout?</a>"); } } } ?> </body> </html> <?php ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.