[email protected] Posted January 25, 2010 Share Posted January 25, 2010 I'm just starting to use PHP Sessions. I have a simple test case to see how Sessions behave which was derived using an example from a reference text. I have two scripts (Code samples below), TESTD.php and TESTE.php, each of which has a link pointing to the other. I use start sessionstart () in each of them. Using the links, I can toggle back and forth and the Session ID remains the same and a test variable which counts the toggles keeps the correct count as I toggle back and forth. PROBLEM: When script TESTE.php runs, I gets a Warning Signal (Sample below) that I don't understand. HELP NEEDED: I need to understand what I'm doing wrong that is causing the warning signal and how to eliminate it. Samples are attached as follows.... In attached file PHPFreakshelp-02.txt 1. TESTD.php CODE 2. TESTE.php CODE 3. TESTD display 4. TESTE display which includes the Warning The Warning is as follows... Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/unitcons/public_html/unitresearch02/TESTE.php:2) in /home/unitcons/public_html/unitresearch02/TESTE.php on line 9 All help is greatly appreciated. Bob G. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/189703-php-session-warning-question/ Share on other sites More sharing options...
[email protected] Posted January 25, 2010 Author Share Posted January 25, 2010 Sorry...there are two typo's in the code examples that I included in the attachment PHPFreakshelp-02.txt that I attached to my post. They are missing brackets needed to close a function. The file attached to this reply, PHPFreakshelp-02b.txt corrects the error. Bob G. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/189703-php-session-warning-question/#findComment-1001173 Share on other sites More sharing options...
laffin Posted January 25, 2010 Share Posted January 25, 2010 U forgot to mention you do have error reporting on, and php probably sent error messages when you called your function, as undefined variables. which is a simple fix, just define the variables before sending it to your function $sessionid=$FBemail=$FBVisitCount=null; sessionstart ($sessionid, $FBemail, $FBVisitCount) ; function sessionstart ($sessionid, $FBemail, $FBVisitCount) when using sessions, you cant send any display code (this includes error reporting) so its good practice not to use functions to start a session but use session_start immediately in the script. <?php session_start(); this way, you can avoid the error reporting sending display code Quote Link to comment https://forums.phpfreaks.com/topic/189703-php-session-warning-question/#findComment-1001177 Share on other sites More sharing options...
[email protected] Posted January 25, 2010 Author Share Posted January 25, 2010 laffin, Thanks for trying but your diagnosis is incorrect. None of your recommendations corrected the problem. 1. Re. Warning: The line it references is "session_start () ;" and it states "Cannot send session cache limiter - headers already sent" so it is related to a session variable, not generic variables. I don't know how to deal with the headers mentioned. 2. Re. error reporting: I did not realize that I could turn off error reporting but I actually don't want to turn it off. So, I still need help. Php Freaks....Please chime in. Cheers, Bob G. Quote Link to comment https://forums.phpfreaks.com/topic/189703-php-session-warning-question/#findComment-1001356 Share on other sites More sharing options...
laffin Posted January 26, 2010 Share Posted January 26, 2010 if you have the above, than you should also check before the <?php opening tag, its common to see this error because of a newline or space before the <?php tag. there should be nothing in front of <?php tag, it should be the very first line, otherwise your sending out display code. Quote Link to comment https://forums.phpfreaks.com/topic/189703-php-session-warning-question/#findComment-1001641 Share on other sites More sharing options...
teamatomic Posted January 26, 2010 Share Posted January 26, 2010 <?php sessionstart ($sessionid, $FBemail, $FBVisitCount) ; function sessionstart ($sessionid, $FBemail, $FBVisitCount) { global $sessionid, $FBemail, $FBVisitCount ; session_start();<<<<<<< Move this to right under the php start tag HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189703-php-session-warning-question/#findComment-1001644 Share on other sites More sharing options...
[email protected] Posted January 26, 2010 Author Share Posted January 26, 2010 teamatomic, laffin... Thanks again for trying but I tested all of your suggestions previously and they did not change the behavior. However, I did find a change that eliminated the problem. I don't know why the problem was eliminated by this. Maybe you can explain. Here's the story... I got into this fix when I found example code for counting the times a session is invoked. That code is in my prior samples but repeated below in part. I thought the Warning might have something to do with a session variable and the only one I had, other than sessionid(), was $_SESSION['count']. Experience told me to change something so I changed the term 'count' to 'visitcount' in all instances and the Warnings stopped and the code worked as I expected it should in the first place. Note that the code was the same in TESTD as it was in TESTE but TESTD never generated the Warning. I changed the term 'count' in both of the files but I may not have needed to do that in TESTD. CODE EXCERPT ....if (empty($_SESSION['count'])) { $_SESSION['count']=1 ; } else { $_SESSION['count']++; ) ..... NOTE: I'll leave this item open for a bit to see if anyone can explain why my change elimianted the problem. Cheers, Bob G Quote Link to comment https://forums.phpfreaks.com/topic/189703-php-session-warning-question/#findComment-1001690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.