Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP redirection using header

My web structure is


         Header-of-page

Nav Link || iFrame


       Footer

I'm Trying to handle session timeout, when session has timeout I'm trying to redirect page to login page, this works fine(session timeout).

Problem: When I'm redirecting the page,login page is displayed in iFrame, which is not expected.

How can I redirect to login page(whole window),rather than opeing it in iFrame.

I Tried: 1. using header 2. using javascript(Commented)

<?php session_start();

$timeout = 1; // Set timeout minutes
$timeout = $timeout * 60; // Converts minutes to seconds

if (isset($_SESSION['timeout'])) 
{
    $session_life = time() - $_SESSION['timeout'];
    if ($session_life > $timeout) 
    {
        session_destroy();
        header("Location: login.php?msg=timeout");
        // echo '<script language="javascript">'; 
                    // echo 'window.location.replace("login.php");';
                    // echo '</script>';
    }
}
$_SESSION['timeout'] = time();

?>

Please guide me for this issue. Thanks!

like image 942
Emma Avatar asked Aug 20 '13 10:08

Emma


People also ask

How do I automatically redirect in PHP?

To set a permanent PHP redirect, you can use the status code 301. Because this code indicates an indefinite redirection, the browser automatically redirects the user using the old URL to the new page address.

How redirect URL in PHP?

Redirection from one page to another in PHP is commonly achieved using the following two ways: Using Header Function in PHP: The header() function is an inbuilt function in PHP which is used to send the raw HTTP (Hyper Text Transfer Protocol) header to the client.

How do I redirect an index PHP to another page?

Answer: Use the PHP header() Function You can simply use the PHP header() function to redirect a user to a different page. The PHP code in the following example will redirect the user from the page in which it is placed to the URL http://www.example.com/another-page.php . You can also specify relative URLs.

What is use of header () function in PHP?

The header() function in PHP sends a raw HTTP header to a client or browser. Before HTML, XML, JSON, or other output is given to a browser or client, the server sends raw data as header information with the request (particularly HTTP Request).


2 Answers

Try this: window.top.location.href = "http://www.site.com";

As long as this is on the same domain name.

More here: Redirect parent window from an iframe action

like image 99
Grant Avatar answered Sep 28 '22 00:09

Grant


use this one

in script window.parent.location='http://localhost/users/login.php'

or follow this link

https://forums.digitalpoint.com/threads/button-to-navigate-to-a-new-page-but-exit-the-iframe-too.1846291/

hope you will get solution.

like image 30
Lucifer Avatar answered Sep 27 '22 23:09

Lucifer