Session Start Error

php is displaying errors on my page

Page 1 of 1

11 Replies - 3317 Views - Last Post: 30 December 2010 - 05:48 AM Rate Topic: -----

#1 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Session Start Error

Posted 29 December 2010 - 10:58 AM

Hi everyone,

Im having a few errors with my PHP im creating a login/registration for my site and i keep getting these errors messages at the top of every page.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\index.php:1) in C:\xampp\htdocs\index.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\index.php:1) in C:\xampp\htdocs\index.php on line 3

Here is a snapshot:

Posted Image

here is my session start code
<?php

session_start();

?>


Im thinking it could be that i configured my Xampp wrong but i really dont know.

thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Session Start Error

#2 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Session Start Error

Posted 29 December 2010 - 11:12 AM

Hi,

This is a pretty common. It is near the top of the Giant PHP List of Common Problems. As it states in the link the problem is due to information of any kind being sent to the browser before session_start() is called. If you are using session in your project be sure to use session_start before any output is sent. Even a blank line before <?php Would cause a problem because line 1 is still output. Hope this helps.

This post has been edited by Jstall: 29 December 2010 - 11:13 AM

Was This Post Helpful? 1
  • +
  • -

#3 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Session Start Error

Posted 29 December 2010 - 11:28 AM

View PostJstall, on 29 December 2010 - 10:12 AM, said:

Hi,

This is a pretty common. It is near the top of the Giant PHP List of Common Problems. As it states in the link the problem is due to information of any kind being sent to the browser before session_start() is called. If you are using session in your project be sure to use session_start before any output is sent. Even a blank line before <?php Would cause a problem because line 1 is still output. Hope this helps.


Hi thanks for the tip but these are my first few lines i dont have any blank lines and im not sure what else could be causing it.


<?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>
    <title>CarbonStudios</title>
    <link type="text/css" rel="stylesheet" href="style.css" />


could this be caused by something later in the code?
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Session Start Error

Posted 29 December 2010 - 11:37 AM

Something is starting output to the browser before <?php, whether it's a blank line or something else, like perhaps a Unicode Byte Order Marker (BOM). What are you using to edit your files? If it's Notepad, suspect the BOM.
Was This Post Helpful? 0
  • +
  • -

#5 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Session Start Error

Posted 29 December 2010 - 11:38 AM

i am using Visual studio 2010 and there are no blank lines before the <?php
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Session Start Error

Posted 29 December 2010 - 12:01 PM

Can you upload index.php as an attachment?
Was This Post Helpful? 0
  • +
  • -

#7 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Session Start Error

Posted 29 December 2010 - 12:12 PM

Here you go

Attached File(s)

  • Attached File  index.php (4.78K)
    Number of downloads: 36

Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Session Start Error

Posted 29 December 2010 - 12:45 PM

It is as I suspected. There is a Unicode BOM at the start:

Attached Image

The UTF-8 BOM is EF BB BF, as per here.

You need to change how Visual Studio saves the file so that's it's just regular text.
Was This Post Helpful? 0
  • +
  • -

#9 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Session Start Error

Posted 29 December 2010 - 12:48 PM

View PostJackOfAllTrades, on 29 December 2010 - 11:45 AM, said:

It is as I suspected. There is a Unicode BOM at the start:

Attachment Screen shot 2010-12-29 at 2.41.19 PM.png

The UTF-8 BOM is EF BB BF, as per here.

You need to change how Visual Studio saves the file so that's it's just regular text.


im uninstalling visual studio as it becomes more and more of a pain how would i change so it saves the right way in notepad++?
Was This Post Helpful? 0
  • +
  • -

#10 Sadin56  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 183
  • Joined: 19-December 10

Re: Session Start Error

Posted 29 December 2010 - 01:09 PM

Never mind ive fixed the BOM issue im going to be using Notepad++ as it is easier.
Was This Post Helpful? 0
  • +
  • -

#11 Huzi94  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 119
  • Joined: 14-November 09

Re: Session Start Error

Posted 30 December 2010 - 03:11 AM

Hey, I tried your attachment on my Ubuntu Box and no errors were returned. I think you should switch to a Linux OS, you would not get a hard time coding php.
Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Session Start Error

Posted 30 December 2010 - 05:48 AM

OS has nothing whatsoever to do with coding PHP.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1