Page 1 of 1
Check for Parent Window
Posted: Mon Apr 27, 2009 8:34 am
by agravayne
Hello,
Is it possible in PHP to check wether a page has a parent? I have a site that uses iframes in certain parts. The site has a timeout so after a certain time if left when the user clicks in one of the iframes it times out and takes them to the homepage - but that appears within the iframe!
What I need it to do is detect that its in an Iframe and if so refresh the parent not the child.
This is the function that checks.
Code: Select all
function CheckLogin()
{
if(!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] != "LoggedIn")
header("Location: http://www.url.com/");
}
So could I adapt this?
Many thanks
Scott
Re: Check for Parent Window
Posted: Mon Apr 27, 2009 9:36 am
by jazz090
no u cant, u have to run that code on each frame
Re: Check for Parent Window
Posted: Mon Apr 27, 2009 9:58 am
by user___
There is, but you will depend on JavaScript. Tell us more about what you are trying to do so that we can suggest a workaround.
Re: Check for Parent Window
Posted: Mon Apr 27, 2009 10:19 am
by agravayne
Well,
We are using DHTMLX with layouts and accordions. The Accordion Cells load from a seperate URL - they basically behave like iframes. Every page I load has the same check in it - which checks wether the users session has timed out or not? If it has then any action on that will redirect the page to the home page where they can log in again. However if this occures in the iframe the home page loads in the iframe. It should force the whole page to reload instead.
I suppose the way to do it would to have the detection on the home page so that if it finds itself loading into an iframe it would reload the parent. Is that possible using javavscript?
Scott
Re: Check for Parent Window
Posted: Mon Apr 27, 2009 12:58 pm
by jazz090
user___ wrote:There is, but you will depend on JavaScript. Tell us more about what you are trying to do so that we can suggest a workaround.
what u mean JS? he obviously has server side code and u want to execute with JS?
Re: Check for Parent Window
Posted: Mon Apr 27, 2009 2:44 pm
by user___
As far as I understand the JS dependance is not a problem for you so JS is the solution for you.
Let's set it like this. You have a user. His/Her session has expired and they click on a button/link in an iframe. What you shoud do is to check for Session expiration(Obviously you do it).
I suppose you use a cless for taht check. In the method by which you check whether a user has expired you should include a case in which instead of header(); you call a JS which gets your parent window object and redirects it to the home page. In order to do this you can raise a flag when a logout is called from an iframe or from the main windows.
Note:Try that and tell us whether it does the job(It must). If you come to something wiser I would be happy to share. This solution came first to my mind.
Re: Check for Parent Window
Posted: Mon Apr 27, 2009 7:22 pm
by jazz090
yh i think i c what user__ is getting at: u echo out ur java with php into html in the body tag possibly
Re: Check for Parent Window
Posted: Mon Apr 27, 2009 8:22 pm
by Benjamin
Translating the above post:
Yeah, I think I see what user__ is getting at. You echo out your java with PHP into html in the body tag possibly.