[PHP] session_start(); error [PHP]

Junior Spellweaver
Joined
Sep 1, 2008
Messages
130
Reaction score
0
Hey guys.

I'm having abit of confusion woth PHP here..
I'm looking at a quick tut on 'sessions' and here's one that I have been given

PHP:
<?php
session_start();
$_SESSION['views'] = 1;
echo "Page Views:". $_SESSION['views'];
?>

And I'm getting these 2 errors when I go to the page.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\php_work\PRACTISE\Listing 5.3.php:9) in C:\xampp\htdocs\php_work\PRACTISE\Listing 5.3.php on line 33

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\php_work\PRACTISE\Listing 5.3.php:9) in C:\xampp\htdocs\php_work\PRACTISE\Listing 5.3.php on line 33
Pageviews = 1

What's causing it. :$:

Thanks in advanced'
YeImANutter.
[Seniour PHP Coder]
 
You either have:
- Html printed BEFORE session_start
- Have headers() somewhere in your script
- Have a space, a blank rule, or an invisible character in front of your <?PHP tag
 
Yeah.. what Guildjuhh said.. It can actually be anything above the 'session_start()' that's messing it up..

When working with sessions, the top of the PHP document should look like this:
PHP:
<?php
session_start();
//Rest Of Script..

?>
<html>
.....
 
Back