Search code examples
phphtmlframeset

PHP use header location to redirect in the frameset


I use header location in php to redirect to login page after the session is invalid.

The code is simple.

PHP Code:

if($_SESSION['admin_id']){

  header('location:login.php');
}

But the problem happen, while times out , i refresh browser the login.php load in the main frame of my layout.

Here is my layout of frameset code. HTML Code:

>>><frameset rows="135,*" cols="*" frameborder="no" border="0" framespacing="0">

  <frame src="index.php?action_type=top" name="topframe" scrolling="no" noresize="noresize" id="topframe" title="" />
  <!--<fram src ="index.php?action_type=content" name="maiframe" scrolling="no" noresize="noresize" id="mainframe" />-->

  <frameset cols="225,*" frameborder="no" border="0" framespacing="0">

    <frame src="index.php?action_type=menu" name="menuframe" scrolling="no" noresize="noresize" id="menuframe" title="" />

    <frame class="framebordertop" src="index.php?action_type=login-info" name="mainframe" scrolling="auto" noresize="noresize" id="mainframe" title="" />

  </frameset>

</frameset>

<noframes>

</noframes>

Solution

  • <?php
    
    if( ....... ){ //if session is invalid
        die("<script>
            if(typeof(parent) != 'undefined'){
                parent.window.location.href='login.php';
            }else{
                window.location.href='login.php';
            }
        </script>");
    }
    
    ?>
    

    Try this ?