I created a game called Mystic Crusade (www.mysticcrusade.com) and it tends to work perfectly except for one thing, sometimes it doesn't register the session, i guess. For some reason, some of my users have to log in several times before they are logged in to stay. This is what I mean...
Most users log in and it takes them to their "home" page, then they can move around and do stuff in the game.
But some users log in, it takes them to their "home" page (which you have to be logged in to see) but when they try to move around the page, it's like as if they were not logged it. If you are not logged in, it kicks you off the game and you have to sign in again. These users will sign in again and again and it will eventually work. This problem has never affected me, but it does effect some users every time.
I use $_SESSION to register the user, the it takes them to their 'home' page via
[php] header('Location: home.php');
exit;[/php]
and I do start the session on every page with session_start();
Please help me, I just don't understand why it seems to work only some of the time
14 1444
This problem may have more to do with how you are destroying your sessions.
Tell me, what method are you using for keeping the session id?
This problem may have more to do with how you are destroying your sessions.
Tell me, what method are you using for keeping the session id?
I'm sorry, what do you mean? I assume that when you use $_SESSION it keeps the information until the browser is closed.
Here is an example on how I set them up
[php]
$name='collin';
$_SESSION['user'] = $name;
[/php]
Now, $name actually equals the username of the user, that was just an example.
to end the sessions I do this...
[php]
if (isset($_SESSION['user'])) {
unset($_SESSION['user']);
}
[/php]
which is located at logout.php
if someone tried to look at my website earlier, it was down because I was trying to figure it out, but I failed to do so. Someone please still help me.
if someone tried to look at my website earlier, it was down because I was trying to figure it out, but I failed to do so. Someone please still help me.
Come on, there has to be someone that can help me
Come on, there has to be someone that can help me
I'm sorry, but you still haven't answered my question as to how you are handling Sessions. Are you using a Cookie to store the Session ID, or are you passing it around via POST or GET?
The way I usually log out is like so:
[php]
function logout()
{
$_SESSION = array();
session_regenerate_id(true);
session_destroy();
}
[/php]
Methinks that your users may have a problem with their PHPSESSID Cookie getting removed, either by your system or by clearing the cache.
I've never really totally understood sessions, so I would have to guess that I use cookies. I defiantly don't do anything with post and get as far as sessions go.
I changed the way I delete sessions to how you showed me you did it. I currently don't know if that fixed anything (The problem doesn't occur with me).
Um... so I hope I answered your question on how I handle the sessions.
When I make the sessions I say something like
$_SESSION['username'] = $username;
I would suggest, then, to read the article about Session Handling Functions. In particular, focus on the section about passing the session id.
Right, I knew all of that. I did some other research before I saw this post and found out that I pass the sessions by cookies. This really confuses me because it works after a few attempts at it. I'll see if changing the way the sessions are deleted does anything
So yeah, I talked to my friend who has the problem and it still occurs. He logged on to the site (took him two tries) then he logged out, closed the browser, reopened it, and it still took him two tries to log in.
So yeah, I talked to my friend who has the problem and it still occurs. He logged on to the site (took him two tries) then he logged out, closed the browser, reopened it, and it still took him two tries to log in.
What I think is happening is that your first login is not correctly setting your Session ID in your client's Cookie.
If you have Firefox, you can watch your cookies as you go through your site.
Tools->Options->Privacy->Show Cookies.
Enter in your server's URL as a filter.
Watch what your PHPSESSID cookie contains the first time you try logging in (unsuccessfully), and compare it to the second time you log in (success).
Okay so talking to my friend, we found out that it was an entirely different problem. http: www.mysticcrusade.com looks the exact same as http://mysticcrusade.com, but it handles the sessions completely differently. My friend had the site bookmarked as mysticcrusade.com instead of www.mysticcrusade.com, so he would have to log in twice. Now i'm wondering, how do i redirect people from mysticcrusade.com to www.mysticcrusade.com to prevent the problem from happening again? is there like a
(pseudocode)
if(header="http://mysticcrusade.com")
{
//make header http://www.mysticcrusade.com
}
edit: In fact, the site works perfectly fine if I leave off the www. for any website I want to go to. I don't even know how that got there
Okay so talking to my friend, we found out that it was an entirely different problem. http:www.mysticcrusade.com looks the exact same as http://mysticcrusade.com, but it handles the sessions completely differently. My friend had the site bookmarked as mysticcrusade.com instead of www.mysticcrusade.com, so he would have to log in twice. Now i'm wondering, how do i redirect people from mysticcrusade.com to www.mysticcrusade.com to prevent the problem from happening again? is there like a
(pseudocode)
if(header="http://mysticcrusade.com")
{
//make header http://www.mysticcrusade.com
}
edit: In fact, the site works perfectly fine if I leave off the www. for any website I want to go to. I don't even know how that got there
This might not be an entirely different problem. You see, a Cookie has a hostname associated with it. If one you are at mysticcrusade.com and create a Cookie, then redirect to www.mysticcrusade.com, and look for the Cookie, it will not be there.
There is a tool you can use, depending on the level of control you have over your server. If you are using Apache, mod_rewrite will allow you to create rules for URLs. This is the preferred method.
The other option you have is to put this code on your opening page:
[php]
if($_SERVER['HTTP_HOST'] != "www.mysticcrusade.com") header("Location: www.mysticcrusade.com");
[/php]
The problem with this method is that it will not work if a user bookmarks a specific page on your site.
:D Okay! Everything should turn out all right then. I asked my server to do that to apachie for me, and i added the code
[php]
if($_SERVER['HTTP_HOST'] != "www.mysticcrusade.com") header("Location: http://www.mysticcrusade.com");
[/php]
and that seems to work alright. Hopefully my problem is totally fixed now. Thank you SO much for your help, it's amazing how such a simple thing can cause such a great deal of stress. Now Mystic Crusade is the best website ever made again, yay!
haha, seriously, thank you very much for your help.
:D Okay! Everything should turn out all right then. I asked my server to do that to apachie for me, and i added the code
[php]
if($_SERVER['HTTP_HOST'] != "www.mysticcrusade.com") header("Location: http://www.mysticcrusade.com");
[/php]
and that seems to work alright. Hopefully my problem is totally fixed now. Thank you SO much for your help, it's amazing how such a simple thing can cause such a great deal of stress. Now Mystic Crusade is the best website ever made again, yay!
haha, seriously, thank you very much for your help.
Glad to hear that things work for you now, and I'm happy I was able to help.
Hope things go well for your site; come back if you need any more help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Taz |
last post by:
comp.lang.php,
I have recently launched the new Planet-Tolkien.com, one would think
that writing a message board from scratch and a dynamic weather
system, a simple session login would be the...
|
by: Phil Powell |
last post by:
What is the most standardized method of utilizing the CURL functions
in PHP (version 4.3.2) to be able to retrieve the contents of a remote
URL that happens to be dependent upon $_SESSION for its...
|
by: comp.lang.php |
last post by:
This is an urgent request (as always)
generate_admin_customer_position_dropdown($customerResult,
$customerResult->id);
print_r($_SESSION);
This code will generate an HTML dropdown as...
|
by: axlq |
last post by:
Someone please tell me if I've discovered a PHP bug.
I'm sitting in front of several computers on my home network, behind
a NAT firewall/router. I am testing my web site on these different...
|
by: bartdlr |
last post by:
Hi,
I got a problem to access the $_SESSION variable in my script.
I wrote some login code: if the user logs in with his name and password
a user object is stored in the $_SESSION variable.
...
|
by: damezumari |
last post by:
When a user logs in to my site http://iwantyourquestion.com I set
$_SESSION to true if his username and password are OK.
When he calls a page I check if $_SESSION is true. If it
not I ask him to...
|
by: nathj |
last post by:
Hi,
I am trying to get $_SESSION to work on my site. In order to learn this an dunderstand it better I have built two very simple test pages to see if i can access $_SESSION on both pages.
...
|
by: dpinion |
last post by:
Greetings,
I am trying to do some simple session stuff. However it does not seem
as though the session variable is being created for my site. I am
running the latest version of PHP and apache that...
|
by: nathj |
last post by:
Hi,
I am having a spot of bother with the use of $_SESSION. They are gernally working absolutely fine with one exception.
On my form I have a capthca security image, when this image is built...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |