Reputation: 1224
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?
Upvotes: 0
Views: 1566
Reputation: 8768
try this:
<?php
if(!isset($_SESSION["login"]))
{
?>
<script>
if(self.location.href != top.location.href){
top.location = '/login.php';
}
</script>
<?php
}
?>
Upvotes: 2
Reputation: 34867
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"
Upvotes: 1
Reputation: 974
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
Upvotes: 1
Reputation: 25164
If you can use Javascript, use top
to access the top parent page, and for instance redirect it to the login page.
Upvotes: 2