Page 1 of 1

IE7 and PHP sessions... PLEEEEEASE HELP

Posted: Wed Nov 15, 2006 9:18 am
by Gooner
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi

I am pulling my hair out over this problem, and am getting to the stage where I'm gonna scream.

All these pages work perfectly on IE6, Firefox, Netscape etc, but I have come across a problem when testing them on IE7.

Here's the problem:

I have a web based system where a user logs into the site. Upon signing in, a number of $_SESSION variables get populated with data, so that the subsequent pages know that he is allowed to visit them, and who he is.

One of these variables is:

$_SESSION['username']

At the top of all subsequent pages, the php script reads:

Code: Select all

<?php
session_start();
if (!isset($_SESSION['username'])) { 
header("Location:unauthorised.php"); 
exit;
}
?>
This effectively checks to see if the user is logged in, and if not, sends them to the "unauthorised" page.

This check works fine.

However, on one of these subsequent pages, I have a link that opens a new window with some information, using the standard <a tag. This is the link :

<a href="new_page.php" target="_blank">Click here</a>

Now, this "new_page.php" also has the script that checks to see if the user logs in.

This new page is displayed fine.

HOWEVER, and this is my problem........

When I close this new window (using IE7 - it works fine in other browsers), and am left with the original page with the link on it, my session data seems to disappear. If I click on refresh, I'm taken to my "unauthorised" page.

WHY IS THIS HAPPENING IN IE7 ??????

So, to recap.........

1) User logs in and session variable stores $_SESSION['username']
2) User goes to new page (page checks to see if logged in - which he is)
3) User click on link on this page which opens new window (using target="_blank").
4) This new window displays fine (page checks to see if logged in - which he is)
5) Close this new window, leaving the original page with the link on
6) Refresh the page (or click the link again) and all session data is lost - sent to unauthorised page

This is only a problem in IE7.

Can someone please suggest a workaround for this issue. I'm almost positive it's a IE7 fault, but am amazed that there aren't loads of people with this issue posting on forums.

Many many thanks for any help you can give


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Nov 15, 2006 11:45 pm
by dibyendrah
Try using print_r($_SESSION) or var_dump($_SESSION) after session_start(); using IE 7 if session is working or not. This will be very helpful for initial debuggin.

Posted: Thu Nov 16, 2006 3:37 am
by Gooner
dibyendrah wrote:Try using print_r($_SESSION) or var_dump($_SESSION) after session_start(); using IE 7 if session is working or not. This will be very helpful for initial debuggin.
Thanks for your reply.

I did what you suggested on both the page that contains the link (call it parent) , and the page that "pops up" after clicking the link (child).

The parent page displayed all session data fine when first called. Refreshed it, and it still displayed.

I clicked on the link to bring up the new "pop-up" window, and this page displayed all the session data correctly as well.

I left the popup open, and refreshed the parent page, and the session data was all still there.

I then closed the pop-up (child page). I refreshed the parent page and the session data was all gone.

Weird !

As a test, I changed the link on the parent page to load the page in the same window, rather than a pop-up (I can't leave it like this however). All session data remained perfectly. It only seems to be a problem with IE7 and with opening a page using the target="_blank" code.

Any other ideas?

Thanks again for all your help.

Posted: Thu Nov 16, 2006 11:05 am
by dibyendrah
I have to try this before I give you a reply.