Bizar behavior by sessions on another server

Discussion in 'Web Hosting' started by gandalf117, Nov 17, 2009.

  1. #1
    Why do sessions on the other server perform differently than sessions on my server?

    hi, everyone,
    I'm building a website and when the user logs in successfully it registers a session with user's information. I use the following code to get my sessions:

    session_start();
    session_register("username");
    session_register("userId");
    $_SESSION['username'] = $username;
    $_SESSION['userId'] = $id;

    header("Location: index.php");

    I simply register the sessions and redirect the user to the home page so that the user doesn't even see and know the log in page. On the index page I simply use session_start(); and if(isset($_SESSION['username'])) $username = $_SESSION['username'] to get the username and display it in the welcoming message. That's it! As simple as that.

    Now all of this works just fine on my localhost apache server but it doesn't work exactly the same way when I upload it on another server. On the other server the user has to log in correctly twice in a row so that the sessions are registered correctly and display a welcoming message with the username on the index page. After the first successful log in it just doesn't find any registered sessions which is absurd, because they should have been registered!
    What is even more absurd is that after the second successful log in (when the sessions are now registered correctly), then log out (which is simply session_destroy(); and redirect to index when there are no registered sessions now), then if you log in again it works as it should from the first time. If you restart the browser (exit and come back, not refresh)the same quirk happens again.

    What is this?
    Since it works perfectly on my server I think it has to do with the way the other server is configured. But how does one reconfigure that?
    Is that really the problem?
    If not that what could it be?
     
    gandalf117, Nov 17, 2009 IP
  2. gandalf117

    gandalf117 Active Member

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    I managed to figure it out myself :)

    The problem was that I was using absolute rather than relative links. This was causing the sessions to get lost for some reason. I still can't understand why it worked from the second try and how it worked at all but it's not that important any more. thanks for trying to help
     
    gandalf117, Nov 18, 2009 IP
  3. Matt21

    Matt21 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    glad that you sorted it out :)
     
    Matt21, Nov 18, 2009 IP