IE7. Annoys. Me.
I play an MMORPG on an account that I share with my Sister-in-law and her husband. I’ve scripted a webpage that keeps track of who’s logged in so we don’t log in on top of each other and boot each other off. I’ve written this script as one page that stores data in a database and restrieves it. Because of how the data is transmitted to the database from the web page (via the HTML POST method), under normal conditions refreshing the page by hitting f5 or clicking the refresh button will warn you that this will repeat any action you just took (sign you in again, or attempt to sign you out again, etc.). If the user clicks “OK” and resubmits the data, it can cause problems with who appears to be playing.
To get around this, I use Sessions. Basically, it puts a cookie on the user’s computer that stores the POST information, clears the POST data, and the script uses the session information to interact with the database. I used the following code, though I don’t remember where I found it, to use sessions:
session_set_cookie_params(1);
session_start();
if(!empty($_POST)) {
$_SESSION+=$_POST;
header(”Location: ” . $_SERVER['SCRIPT_NAME']);
session_write_close();
exit();
}
One of the features of setting a Session cookie is the abilit to specify when the cookie will expire. If you don’t specify an amount of time for the cookie’s lifetime, it expires when the browser is closed. As long as the cookie has not expired, trying to sign in or out will just repeat the last action you did, whose information is stored in the cookie.
I have set a lifetime for my session cookies of 1 second. (That’s what the session_set_cookie_params(1); line in the above code does) The life time is defined in seconds, it’s the only unit you can use, so when you specify the lifetime, you just use a number (”1″ in my case). IE6, FF, Opera, Safari, and every other conceivable web browser handle this correctly, and I don’t have problems.
My in-laws just upgraded to IE7, and the page stopped working for them. They’d try to sign out, and it would sign them in again, or if they’d just signed out successfully (say my sister-in-law had been playing and now the husband wanted to), no one would be able to sign in again. So I started testing this, and it appears that IE7 interprets the lifetime part of the cookie as being minutes instead of seconds. After a lot of putzing around last night, I finally figured out how to manually expire the cookie once the page had finished loading, using the code posted below (which I pulled from the page for session_destroy at php.net) at the end of the script, and it’s working again now. The first line clears the $_SESSION autoglobal. The if statement looks to see if there’s still an unexpired cookie with the appropriate session name, and sets its expiration time 700 minutes in the past (a little overkill, perhaps). The last line destroys the session information.
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(),”",time()-42000,’/');
}
session_destroy();
BUT WHY, OH WHY can Microsoft not write their software to conform to standard specifications? Why? I really, really, dislike IE7 right now.