gandalf117
17 Nov 2009, 06:12 PM
hi, everyone,
Why do sessions on the other server perform differently than sessions on my server?
What is strange is that on the other server you have to log in twice to register the sessions.
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 just 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 have been registered! After redirection to the index page and session_start(); $_SESSION['username'] is empty.
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 and welcome message 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?
Why do sessions on the other server perform differently than sessions on my server?
What is strange is that on the other server you have to log in twice to register the sessions.
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 just 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 have been registered! After redirection to the index page and session_start(); $_SESSION['username'] is empty.
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 and welcome message 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?