session_start Error !!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

session_start Error !!

Post by lazersam »

Hi all
I am very new to PHP and so have lots of newbie questions :)

I am using the session_start() function at the top of my page and get this error...

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/centurio/public_html/PHP/validate.PHP:1) in /home/centurio/public_html/PHP/validate.PHP on line 1

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/centurio/public_html/PHP/validate.PHP:1) in /home/centurio/public_html/PHP/validate.PHP on line 1

the top line looks like this... <?php session_start();

there is nothing before the statement! I have also tried this...

<?php
session_start();

but get the same error! I have searched the web and can't seem to get an explaination. I get the same result from 2 different servers.

Any ideas? Thanks in advance.

Lawrence.
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

Post by lazersam »

It's OK People - I solved it !!!

All I had to do is remove the 3 blank spaces before the " <? "

Der...

Lawrence.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

You got it. As you probably realise by now, you can't have any browser output prior to session_start - whitespace often catches people out.

Also note that session_start doesn't have to be the first thing in the script: can go anywhere before you start echo'ing or any other browser output.
Post Reply