I have included session_start at the top of each page but am creating a website where each page is linked to the header.php, which also has session, does this mean that i would only need 1 session in header.php?
Sometimes, i have been getting session already started notice and i noted that it is not an error, can i ignore this on a live server?
If you have session_start() on top of every page and you include headers.php to these pages. Then headers.php do not need another session_start(). Other way around if headers.php is included to your every page at the top of the pages you can have session_start() only in headers.php and remove it from the top of the pages.
Scenario 1:
somepage.php
session_start();
include 'headers.php';
headers.php // session_start() not needed here anymore.
The difference between a PHP error and notice is that the former also stops script execution. Despite that you should never ignore issues (compare it to the low fuel alert in a car, it will still run … up to a certain point in the future).
As of PHP 4.3.3, calling session_start() after the session was previously started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored.
there is no guarantee it will always be so. It doesn’t make sense to me to leave code with a known error in place simply because one can get away with doing it.
This particular notice at this moment of time won’t break your program and is anyway recommended be dealt with correctly as others have already stated. Will the notice appear on the live server also? That depends on the server/php configuration. Added to that you should never show any notices, warnings or errors to the end user in a live production site. You should log them instead somewhere (most of the time to a logfile).
Please take care that variables in PHP are case sensitive, meaning $_session does not refer to the session variables. For that you must use $_SESSION (all caps).
Also, you must call session_start()before doing anything with $_SESSION