First of all, hello, I am new to the sitepoint forum and I’m from Holland. Recently I purchased the books: PHP Ant OOP solutions vol. 1 and 2.
The permissions system from the second book chapter one generates a notice which I really don’t know how to solve. I know it’s just a notice, but as far as possible I would like te make sure the code works properly, without just removing notices from my error reporting messages.
When I start script 14.php, I get redirected to script 13.php to add my user name and password. If these two are valid, script 14.php checks wich permissions I have and, based on this, I can test some settings.
But when I am logged in, the following notice appears ( in script 14.php )
Notice: A session had already been started - ignoring session_start() in C:\PROGRA~1\EASYPH~1\www\oud\phpant1\SPLIB\Session\Session.php on line 25
I know that the class Session.php says that if a session already exists the function session_start() will do nothing. As this notice also tells me. But I would like to know how to change this class that this notice will not appear again.
If anyone has a good idea, I would be very pleased!
It should be safe enough to comment out the offending line.
Your PHP ini setting is probably set to show all errors and warnings.
If you don’t want to change the code in the script then you can change the PHP ini setting to show no errors or warning but if you are developing on the local machine then this will prove to be a pain in back side.
Thank you for your reply. I understand I can hide all notices.
This is indeed a solution, but in my case, even a notice is an error and I should add some kind of validation to check wether a session is already started, before telling the server to create another session?!
As a rule I would only ever have session_start() at the top of a script… but maybe that’s just me.
I had a quick look at the PHP manual and can’t see a function that checks to see if a session exists… but you could proabably see if one of the default session variables is set and set the session accordingly.
This works perfectly! I will have to test this further, because I just added this to the session class and noticed that the notice didn’t appear anymore.