Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End sessions

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #25348
    AlCapone
    Participant

    Hi, Ok, i am working on a log in script for a site but am having some problems with sessions. I have the form and the php which goes to the mysql server to check if there details are correct but I am having problems sorting out the seesion. After the results have come back saying that there details are correct I have put,

    Code:
    session_start();

    Then i have,

    Code:
    $_SESSION[‘accountName’] = $accountName;
    $_SESSION[‘accountMail’] = $email;
    $_SESSION[‘LoggedIn’] = 1;

    THen i redirect them to another page for members which at the moment just has this code,

    Code:

    Thanks for logging in! You are

    But it is not showing the users accountName, any Ideas?

    Also, the redirect code that I am using is,

    Code:
    print ““;

    But this is not working, I think its because its adding ‘www.mysite.com’ to the page im already on, how can i make it follow the link?

    Many THanks
    Chris

    #60176
    mattvot
    Member

    Hey,

    Take a look at http://www.thesitewizard.com/php/sessions.shtml

    Its a great guide to using sessions. If there is still a problem after using the guide then it would be most probably an error in the code.

    #61002
    slgworks
    Member

    First you should make sure that sessions are supported by your server and that cookies are enabled on your computer.
    Also I would recommend using a php redirect instead of an HTML one. This would look like:

    Code:
    header(Location: /file/index.php);

    For a PHP redirect to work make sure that there is no preceding output to the browser.

    #61181

    I think the original problem is that you didn’t put http:// at the beginning of the URL so it treated it as a file.

    #61659
    whatmonkey
    Member

    I think you need to load the session variables within the script on the second page. You need to have a

    Code:
    session_start();

    on all of your scripts that access the session variables. This will register the session with the script and give you access to the variables.

    #61941

    Exactly what "whatmonkey" wrote is correct. Every page has to have the "session_start()" as the FIRST statement on your page – even before any spaces or anything else.
    Secondly what I fell over some time ago was, that the session management i.e. of firefox does start a new session each time you open a "new" tab i.e. by pressing <ctrl + t> but does use the existing session id of "your current site" if you just forward to a new tab using a link or so.
    You have to make sure that the tab you use is using the same session like the one you expect it to be since otherwise the saved variables of session "A" will not be available on session "B".

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.