the "session_start(), headers sent" problem SOLVED

Problems with the Windows version of XAMPP, questions, comments, and anything related.

the "session_start(), headers sent" problem SOLVED

Postby piotrex » 04. April 2008 15:40

Hello, at the beginning I would like to say that I read the manual and a lot of google answeres for this problem. I am trying to use the sessions - on one page I log the user in, and place a link to another page. Yet on that page I cannot access the $_SESSIONS table - it ise empty (only on my localhost).
I have a php file, which I use to log the user in
Code: Select all
<?
session_start();

//require_once('polacz.php');
require_once('funkcje.php');
require_once('gui.php');


if($_SERVER['REQUEST_METHOD'] == 'POST'){....


as you see, I fetch 2 files
funkcje.php:
Code: Select all
<?php
require_once('polacz.php');


function czyIstnieje($u,   //uzytkownik - login
   $p){   //haslo
   
   $zapytanie = "SELECT login,id FROM logowanie WHERE login='$u' AND haslo='$p'";
   $wynik = mysql_query($zapytanie);
   
   if(mysql_num_rows($wynik) == 1)
      $odp = mysql_fetch_array($wynik);
   if($odp['id']){
      //echo $odp['id'];
      return ($odp['id']);
   }
   else{
      //echo "blad przy zapytaniu - uzytkownik nie istnieje<br/>";
      return -1;
   }
   
};

function zarejstruj($l,$h){
   $zapytanie = "INSERT INTO logowanie (login,haslo) VALUES ('$l','$h')";
   return( mysql_query($zapytanie));
};

function zaloguj($l,$h){
   // szuka cz koles istnieje w bazie danych.
   // jesi tak, to zwraca jego id, jesli nie, to -1
   //$id = czyIstnieje($l,$h);
   $id = 1;
   if($id != -1){
      return $id;
   }
   else{
      echo "nie moæna Cie zalogować!<br/>podałeś niepoprawne dane";
      return -1;
   }
};

?>


gui.php:
Code: Select all
<?php
//session_start();
function pokazRejstracje(){
   // dorobic sprawdzanie poprawnosci przy logowaniu!!!!!
   echo '<form method="post" action="zarejstruj.php" name="rejstracja">';
   echo 'login: <input type="text" name="login"/>';
   echo 'hasło: <input type="password" name="haslo"/>';
   echo 'powtorz hasło: <input type="password" name="haslo2"/>';
   echo 'e-mail: <input type="text" name="email"/>';
   echo '<input type="submit" value="OK"/>';
   echo '</form>';
};

function pokazLogowanie(){
   echo '<form method="post" action="loguj.php" name="logowanie">';
   echo 'login: <input type="text" name="login"/><br/>';
   echo 'hasło: <input type="password" name="haslo"/>';
   echo '<input type="submit" value="OK"/>';
   echo '</form>';
};


?>


and the polacz.php:
Code: Select all
<?php
/* skrypt lazcy sie z baza danych */
mysql_connect(localhost,root,"");
mysql_select_db("dziekanat");

?>


Now, as you see, I do not echo anything out before the "session_start()" function (or do I ?). I get the:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at F:\software\xampp\htdocs\vd\php\loguj.php:1) in F:\software\xampp\htdocs\vd\php\loguj.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\software\xampp\htdocs\vd\php\loguj.php:1) in F:\software\xampp\htdocs\vd\php\loguj.php on line 2

I really don't know what to do. I read about the ZoneAlarm firewall - I don't use it. I looked through the php variables - nothing. I'm desperate. Can anyone help me ?
I use the XAMPP apache server, it is fresh after install. When I upload those files on another server, it works just as I want...
Last edited by piotrex on 05. April 2008 08:44, edited 1 time in total.
piotrex
 
Posts: 3
Joined: 04. April 2008 15:14

Postby Wiedmann » 04. April 2008 15:44

The files are encoded in utf-8?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby piotrex » 04. April 2008 18:12

yes they are
piotrex
 
Posts: 3
Joined: 04. April 2008 15:14

Postby Wiedmann » 04. April 2008 18:35

Don't store your UTF-8 files with a BOM.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby piotrex » 05. April 2008 08:43

OK, so the encoding was wrong :/
but I don't know what happened. I'm using Visual Studio with vsPHP plugin. I've rewritten the scripts from a scratch and they seem to work. Thanks alot guys :)
piotrex
 
Posts: 3
Joined: 04. April 2008 15:14


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 151 guests