nikee
02-04-2010, 05:36 PM
Hey there :)
I'm working on a forum and suddenly, without me changing anything the following error message started to appear on the absolute top of the site. I've read posts on other forums, and searched here, but i can't seem to find a solution. I've looked for white spaces before and after the PHP tag, which some adviced me to remove, but i can't find any. (checked in several editors)
The error message says that the headers is was already sent by line 1 in header.php, but that's the first line on that page. :confused: The header file is included into my index.php file, but i don't have a session_start() there.
Any ideas what's gone wrong here? I'm loosing hair :eek:
Error message:
Warning: session_start() [function.session-start (http://localhost/forum_self/function.session-start)]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\forum_self\header.php:1) in C:\xampp\htdocs\forum_self\header.php on line 1
Header code:
<?php session_start(); ?>
<!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=utf-8" />
<title>Mitt forum - Nicklas Sandell</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<h2><a href="index.php">Mitt forum</a></h2>
<div class="header-right">
<?php
if($_SESSION['username'] !== ''){
$username = $_SESSION['username'];
$connect_host = 'localhost';
$connect_username = 'root';
$connect_password = '';
$connect_db_name = "mittforum";
$connect_tbl_name = "users";
mysql_connect("$connect_host", "$connect_username", "$connect_password") or die(mysql_error());
mysql_select_db("$connect_db_name") or die(mysql_error());
$sql = mysql_query("SELECT * FROM $connect_tbl_name WHERE username='$username'");
$row = mysql_fetch_array($sql);
mysql_close();
}
?>
Välkommen <?php echo $row['name']; ?>
</div> <!-- header-right -->
</div>
<div id="menu">
<ul>
<li><a href="index.php">Hem</a></li>
<li>
<?php
if($_SESSION['username'] == ''){
echo '<a href="login.php">Logga in</a>';
echo '<li><a href="register.php">Registrera ett konto</a></li>';
}else {
echo '<a href="account.php?usr=' . $row['id'] . '">Mitt konto</a>';
echo '<li><a href="logout.php">Logga ut</a></li>';
}
?></li>
</ul>
</div> <!-- menu -->
Thanks in advance! :rolleyes:
EDIT: I forgot to say that it still does work just as normal, so i don't understand why the error is showing up? owh!
I'm working on a forum and suddenly, without me changing anything the following error message started to appear on the absolute top of the site. I've read posts on other forums, and searched here, but i can't seem to find a solution. I've looked for white spaces before and after the PHP tag, which some adviced me to remove, but i can't find any. (checked in several editors)
The error message says that the headers is was already sent by line 1 in header.php, but that's the first line on that page. :confused: The header file is included into my index.php file, but i don't have a session_start() there.
Any ideas what's gone wrong here? I'm loosing hair :eek:
Error message:
Warning: session_start() [function.session-start (http://localhost/forum_self/function.session-start)]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\forum_self\header.php:1) in C:\xampp\htdocs\forum_self\header.php on line 1
Header code:
<?php session_start(); ?>
<!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=utf-8" />
<title>Mitt forum - Nicklas Sandell</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<h2><a href="index.php">Mitt forum</a></h2>
<div class="header-right">
<?php
if($_SESSION['username'] !== ''){
$username = $_SESSION['username'];
$connect_host = 'localhost';
$connect_username = 'root';
$connect_password = '';
$connect_db_name = "mittforum";
$connect_tbl_name = "users";
mysql_connect("$connect_host", "$connect_username", "$connect_password") or die(mysql_error());
mysql_select_db("$connect_db_name") or die(mysql_error());
$sql = mysql_query("SELECT * FROM $connect_tbl_name WHERE username='$username'");
$row = mysql_fetch_array($sql);
mysql_close();
}
?>
Välkommen <?php echo $row['name']; ?>
</div> <!-- header-right -->
</div>
<div id="menu">
<ul>
<li><a href="index.php">Hem</a></li>
<li>
<?php
if($_SESSION['username'] == ''){
echo '<a href="login.php">Logga in</a>';
echo '<li><a href="register.php">Registrera ett konto</a></li>';
}else {
echo '<a href="account.php?usr=' . $row['id'] . '">Mitt konto</a>';
echo '<li><a href="logout.php">Logga ut</a></li>';
}
?></li>
</ul>
</div> <!-- menu -->
Thanks in advance! :rolleyes:
EDIT: I forgot to say that it still does work just as normal, so i don't understand why the error is showing up? owh!