0

I have a site with an iframe. Booth, the site and the site in the iframe are checking $_SESSION["login"]. So if the Session gets expiered the user will be logged out.

Problem: When the user hangs around the site for some time and the session gets expiered the login-page will appear in the iframe. (for example he clicks a link with target="iframe") I want the login-page to appear in the parent.

Possible?

iceteea
  • 1,214
  • 3
  • 20
  • 35
  • Have you considered using something other than an IFRAME to display your sub-content? http://stackoverflow.com/questions/2102878/better-alternative-to-an-iframe - Not sure, but I think loading your page into a DIV via AJAX will make it so some forms of redirect will redirect the whole page instead of just the sub-page, as the browser will (sort of) treat it all as one page. See also: http://stackoverflow.com/questions/4213122/reload-page-from-ajax-loaded-subpage – Merlyn Morgan-Graham Dec 06 '11 at 09:54

4 Answers4

2

If you can use Javascript, use top to access the top parent page, and for instance redirect it to the login page.

Mic
  • 24,812
  • 9
  • 57
  • 70
2

try this:

<?php 
   if(!isset($_SESSION["login"]))
   {
?>
<script>
   if(self.location.href != top.location.href){
       top.location = '/login.php';
   }
</script>
<?php
   }
?>
jerjer
  • 8,694
  • 30
  • 36
1

If session expire time is not mandatory, why not set the session to not expire until the browser is closed?

<?php ini_set("session.gc_lifetime","0"); ?>

this setting sets that the session will not expire until the browser is closed. If you have access to php.ini you can set that to default

GuZzie
  • 974
  • 1
  • 6
  • 23
1

Add a check to your login page wheter or not it is loaded inside the iframe, like so:

var isInIFrame = (window.location != window.parent.location) ? true : false;

If it evaluates to true, try reloading the page in the top window, like so:

window.top.location.href="/login.php"
Oldskool
  • 34,211
  • 7
  • 53
  • 66