xProteuSx Posted December 19, 2006 Share Posted December 19, 2006 I am trying to create a website that you can register with. As a result, I am trying to implement sessions so that registered users can have additional functions built into the site. So on index.php I have a form where the user enters his Handle and Password, and this gets passed on to login.php which runs the code to verify the username/password combo and thus the login. At the top of index.php, above the header I have the following code:[code]<?phpsession_start();session_register("mcathandle");session_register("mcatemail");session_register('mcatdatejoined');session_register('mcatrandomkey');session_register('mcatvisits');session_register('mcatlastvisit');session_register('mcatquestionsanswered');session_register('mcatcorrectanswers');session_register('mcatpercentcorrect');session_register('mcattotalscore');session_register('mcatpagesviewed');session_register('mcatvisitbonus');session_register('mcatactivity');?>[/code]If the login is successful the following occurs:One, the proper db is selected, connected to, and values are extracted and assigned to all of the registered session variables above, and two, the variables are output to the screen. Now, this works just fine and dandy, but when I go to another page on the site, and call up any of the registered session variables, the values are blank. What am I doing wrong? Do I have to put something at the top of each page to signify the implementation of the session? What do I do to carry the values over?Please help. My text books are of no help, and the examples that I am finding online are not helpful. Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/ Share on other sites More sharing options...
marcus Posted December 19, 2006 Share Posted December 19, 2006 Try echoing $_SESSION and see what you get Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144112 Share on other sites More sharing options...
fert Posted December 19, 2006 Share Posted December 19, 2006 you should use session_register you should use $_SESSION['value_name']="value"; Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144114 Share on other sites More sharing options...
xProteuSx Posted December 19, 2006 Author Share Posted December 19, 2006 I created a session.php file that consisted of:<?phpecho "$_SESSION";?>and when I viewed it it was blank. Why is my session not working? Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144117 Share on other sites More sharing options...
xProteuSx Posted December 19, 2006 Author Share Posted December 19, 2006 I think that the whole problem is in the fact that the values for the variable are assigned after the header is sent. How can I get around this problem? After all, I do not want the values to be assigned to the variables before the login process is complete, and this completion can only take place after the header has been sent. Is there any way to do this using a single page? Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144132 Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 try doing this:[code=php:0]<?phpprint_r($_SESSION);?>[/code]and see if that outputs anything... Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144145 Share on other sites More sharing options...
kenrbnsn Posted December 19, 2006 Share Posted December 19, 2006 I believe [b]fert[/b] meant to say "you should [b][color=red]not[/color][/b] use session_register".Ken Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144146 Share on other sites More sharing options...
xProteuSx Posted December 19, 2006 Author Share Posted December 19, 2006 fert, I have tried it your way and I still cannot get any variables to stick to the session. Also, the print_r command produced a blank page, as before. It seems that the session is not being initialized. I should mention, though I am unsure what this means exactly, that Global Variables on my server are disabled. Could this be part of the problem? Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144150 Share on other sites More sharing options...
corbin Posted December 19, 2006 Share Posted December 19, 2006 session_start();Should always be at the very top of any page that uses sessions... Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144162 Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 session_start() is at the top of that page. but it may not be at any others. try placing the print_r($_SESSION); after registering all those sessions... Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144164 Share on other sites More sharing options...
corbin Posted December 19, 2006 Share Posted December 19, 2006 [quote author=xProteuSx link=topic=119193.msg487843#msg487843 date=1166491352]I created a session.php file that consisted of:<?phpecho "$_SESSION";?>and when I viewed it it was blank. Why is my session not working?[/quote]I didnt see it in there... Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144174 Share on other sites More sharing options...
xProteuSx Posted December 19, 2006 Author Share Posted December 19, 2006 Thanks guys. With your help the problem is now solved. It was a matter of putting session_start(); at the top of each page. Also, to print the values of the session variables to the screen I had to use print($_SESSION['variablename']); instead of echo"$variablename"; Quote Link to comment https://forums.phpfreaks.com/topic/31181-solved-sessions-wont-carry-over-to-rest-of-site/#findComment-144190 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.