How to prevent frame navigation.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
karozans
Forum Newbie
Posts: 8
Joined: Mon Sep 15, 2008 5:14 pm

How to prevent frame navigation.

Post by karozans »

Hi everyone. I have a website that uses frames. Using PHP what is the best way to prevent a user from navigating to the subframe directly instead of going through index.htm?

thank
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: How to prevent frame navigation.

Post by tech603 »

One way you could do this, is to use sessions on the main frame. Once the session has been started and the session variable is set you can have the other frames check that the session variable has a value. So on the main frame you could so something like

Code: Select all

 
<?php
session_start();
$_SESSION['frameCheck'] = 'mainFrame';
?>
 
On the other pages you would check for the session but not start one, so this condition can only be true if the main frame is loaded.

Code: Select all

 
<?php
 
if(!isset($_SESSION['frameCheck']) && $_SESSION['frameCheck'] != 'mainFrame' ){
header_location('main frame');
}
?>
 
This in theory should work, this way a session variable for frameCheck would only be valid in the main frame and if they try and navigate away from the main frame to the sub frames it should redirect them.

Hope that helps point you in the right direction.
Last edited by Benjamin on Mon May 18, 2009 4:08 pm, edited 1 time in total.
Reason: Changed code type from text to php.
karozans
Forum Newbie
Posts: 8
Joined: Mon Sep 15, 2008 5:14 pm

Re: How to prevent frame navigation.

Post by karozans »

Yes is sure does. thanks for the help. I was thinking about sessions but I wasn't sure how to implement it.

thanks
Post Reply