...

View Full Version : Warning: session_start() [function.session-start]:.... help? :)



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!

mlseim
02-04-2010, 05:38 PM
Is the script you show above "included" in another script that also has session_start?
Try commenting-out the session_start in the script above and see what happens.

EDIT ....
I now see I didn't read the first post good enough.
Put the session_start in your index script instead of the included one.


.

JAY6390
02-04-2010, 05:43 PM
The error message is pretty self explanatory. You've got an error because you've had output in header.php on the first line. Be sure there are no spaces or blank lines before the <?php as even a single carriage return or space/tab is output and will cause this

nikee
02-04-2010, 05:45 PM
Thanks for the reply mlseim :)

As i said in my first post, the header.php file is included to index.php (and other pages), but none of the pages it's included to has the session_start() function included.

If i comment it out, the error dissapears. But the session function stop working..

nikee
02-04-2010, 05:49 PM
The error message is pretty self explanatory. You've got an error because you've had output in header.php on the first line. Be sure there are no spaces or blank lines before the <?php as even a single carriage return or space/tab is output and will cause this


there's nothing :O Same thing in dreamweaver... :(
http://f.imagehost.org/0446/Screenshot33.png


Now that i re-think, i did change the charset earlier, so that swedish characters is displayed directly. I also opened the header.php file in notepad, and re-saved it in UTF-8 encoding. Can that be why?? :eek:


EDIT: I copied all of the content in header.php, made a new textfile, pasted the code and changed it to php file format. Still not working :(

JAY6390
02-04-2010, 06:00 PM
I have heard that the character encoding makes a difference sometimes yeah. There's something called the Byte Order Mark (http://en.wikipedia.org/wiki/Byte_order_mark) which causes this although I've not played with it and not all that well versed in it. If I remember correctly it was N++ that caused the BOM the last time I saw it. Can you show your code for the index.php up to the include just in case it is that

JAY6390
02-04-2010, 06:02 PM
Here's a link to the last one I saw, and apparently it IS an encodin issue
http://forum.phpvideotutorials.com/showthread.php?t=3456&highlight=byte+order+mark

nikee
02-04-2010, 06:04 PM
Aaaaand i fixed it! :D

I copied the text, created a new file in DREAMWEAVER, pasted the code and saved it. Woala, runs like a dream now!

Thanks for the help though, appreciate it! :rolleyes:

mlseim
02-04-2010, 07:24 PM
Glad you got it ...
sometimes hashing stuff around on here triggers some ideas ... creates "aha" moments.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum