ballouta Posted June 30, 2008 Share Posted June 30, 2008 Hi It is my first session test. Everything was working properly as expected, I took a break and now the same pages and the same code is not working, i couldn't discover where the problem exists. here's the session code from the first page: <?php session_start(); $user=$_POST['user']; $pass=$_POST['pass']; $_SESSION['username'] = "$user"; echo $_SESSION['username']; ?> i am able to see the username after the echo command. in this page i do not have any problem. Page 2: <?php @session_start(); include('CMS/global.inc.php'); $user =$_SESSION['username']; echo "User = $user"; if($_SESSION['username']) { here i have some DB code } else { echo "session not working"; } I cant see the user echoed here and 'session not working' appears. where's the problem? please help Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/ Share on other sites More sharing options...
kenrbnsn Posted June 30, 2008 Share Posted June 30, 2008 Did you close the browser window between the first test and the second test? Closing the browser window deletes the current session. Also, how do you get from the first script to the second? Ken Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578133 Share on other sites More sharing options...
volatileboy Posted June 30, 2008 Share Posted June 30, 2008 If you have already set $_SESSION['username'] you don't need this: $user = $_SESSION['username']; you can just do this: echo 'User: ' . $_SESSION['username']; and like the guy above me says, if you closed the browser window your session data is gone Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578134 Share on other sites More sharing options...
DeanWhitehouse Posted June 30, 2008 Share Posted June 30, 2008 also remove the @ from session_start(); as this stops errors appearing( i think, correct me if i'm wrong) <?php session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578143 Share on other sites More sharing options...
ballouta Posted June 30, 2008 Author Share Posted June 30, 2008 thank you all First, I didn't close the explorer while making my test. Second, I removed that @ and I got this warning: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ballouta/public_html/login.php:7) in /home/ballouta/public_html/login.php on line 28 Third, in page2.php I got this warning too: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ballouta/public_html/credits.php:7) in /home/ballouta/public_html/credits.php on line 38 Note: I just tested the pages again and the result (except the warnings) is correct, BUT when i upload page1.php and page2.php to another host, it is not working. How do I fix the problem mentioned in the warning so i can get to the secnd part? Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578144 Share on other sites More sharing options...
PFMaBiSmAd Posted June 30, 2008 Share Posted June 30, 2008 How do I fix the problem mentioned in the warningSimple, read the warning messages and find what the output is that they are telling you is occurring in each of the files - output started at ..../login.php:7 (line 7) output started at ..../credits.php:7 (line 7) Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578196 Share on other sites More sharing options...
ballouta Posted June 30, 2008 Author Share Posted June 30, 2008 I already did, I had a look on line 7 which is: <link href="layout.css" rel="stylesheet" type="text/css" /> but i don't know if there's any conflict between css and sessions! Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578388 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 ob_start() will solve it but it is only a hack not a solution Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578389 Share on other sites More sharing options...
ballouta Posted June 30, 2008 Author Share Posted June 30, 2008 do i have to add this 'hack' after starting the session, actually never heard about this thanks Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578391 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 actually you declare output buffering before session start it will clear up those errors. but if you turn error reporting on thery will come back Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578393 Share on other sites More sharing options...
PFMaBiSmAd Posted June 30, 2008 Share Posted June 30, 2008 Any page that uses a session should have the session_start() statement at the very beginning of the page. You are putting a session_start() at lines 28/38 in your two files. Quote Link to comment https://forums.phpfreaks.com/topic/112572-solved-session-problem/#findComment-578407 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.