Multiple call to session_start()

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
rasspass
Forum Newbie
Posts: 4
Joined: Mon Mar 14, 2011 12:20 pm

Multiple call to session_start()

Post by rasspass »

I have the following PHP codes:
include.php

Code: Select all

<?php
session_start();
?>
and page.php

Code: Select all

<?php
session_start();
include("include.php");
?>
and get the following warning:
Notice: A session had already been started - ignoring session_start() in C:\wamp\www\session\include.php on line 2
Of course my project has several files but have the same issue as above. How would I solve this without turning warning switches off in php.ini file. Your help is appreciated. Thank you in advance.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Multiple call to session_start()

Post by califdon »

The simplest way is just don't use session_start() in a file that will always be included, and always use session_start() in any other file that needs it. If the main file always has it at the beginning, you shouldn't repeat it in another file that's simply going to be copied into the main one.
Post Reply