Jump to content

[SOLVED] Sessions won't carry over to rest of site ...


xProteuSx

Recommended Posts

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]
<?php
session_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.

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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";
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.