Reputation: 561
I've got the following code to check if the session exists and if it doesn't its created.
session_start();
$loginExists='';
$show=1;
if(isset($_SESSION['username'])){
$loginExists = '<div style="color:#006633; font-family: calibri, Times, serif; font-size:1.3em; font-weight:bold; margin-left:4%; margin-top:2%;">You are already logged in!</div>';
$show = 0;
}
elseif (!isset($_SESSION['username'])){
if (isset($_COOKIE['username'])){
$_SESSION['username'] = $_COOKIE['username'];
$loginExists = '<div style="color:#006633; font-family: calibri, Times, serif; font-size:1.3em; font-weight:bold; margin-left:4%; margin-top:2%;">You are already logged in!</div>';
$show = 0;}
The cookie is set in the following way:
setcookie('username',$row['username'],time() + 10*24*3600,"/mysite/","");
My problem is when i clear coookies in IE8/9 it fails to clear the cookies. I can still navigate to my add form.Not a problem in Firefox or Chrome.
I'm attempting to delete cookies by going to Internet Options > Delete (Browsing History) > Checked Coookies and deleted it.
Very puzzled atm.
EDIT:
add form (how the session is checked):
if (!isset($_SESSION['username'])){
if (isset($_COOKIE['username'])){
$_SESSION['username'] = $_COOKIE['username'];
}
else{
$_SESSION['addForm'] = 1;
header("Location:loginForm.php");
}
So as you can see if the cookie is cleared via the browser it should redirect to the login page.
Upvotes: 1
Views: 296
Reputation: 17720
(Posting answer for completeness, based on comment above)
A tip for IE. Close it down. Go to control panel, find internet settings and clear down the cookies (and files if needed) from there. Then re-open IE. Note that if you leave it open and hit refresh, it still sends the previous cookies - closing it down sorts this out.
Q: Is that a quirk of IE?
It appears to be - I think IE internally loads some cached files and cookies, and clearing down the files doesn't remove them from memory. So if you get this behaviour, close down to remove from memory, then clear the files and re-open.
It's also a "gotcha" in Fiddler (debugger) that if you hit "Resend Unconditionally" from Fiddler, it resend the previous query, including cookies, even if the cookies were subsequently deleted. To be honest, this is what I'd expect, so I'm not saying it's a fault. Just noting that you need to monitor what is being sent as it may not always be what you expect when debugging apps.
Upvotes: 1
Reputation: 48
Did you try to set expiry time for cookies from PHP after setting the session ?
Upvotes: 0