Session sets in iframe(child) how to get the session in parent widnow?

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
mikros
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Nov 03, 2020 10:13 am

Tue Nov 03, 2020 10:17 am

I am having an empty page with an iFrame and inside index.php. When users press log in button it start session with the following code and load catalogue.php.

My html of iframe page:

Code: Select all

    <!DOCTYPE html>
    <html>
    <head>
	    <style>
        html, body, iframe { height: 100%; }
	    html { overflow: hidden; }
	    body { margin: 0px;}
	    </style>
	    <base target="_parent">
    </head>
    <body>
        <iframe src="http://192.168.1.10/index.php" width="100%" scrolling="yes" style="border:none;"</iframe>
    </body>
    </html>
My session code in index.php(on button press):

Code: Select all

    <?php
    session_start();
    $_SESSION['valid'] = true;
    $_SESSION['timeout'] = time();
    header('location:catalogue.php');
    ?>
In catalogue.php i have the following session check.

My session check code:

Code: Select all

    <?php
    session_start();
    if (isset($_SERVER['HTTP_REFERER'])) {
        if ($_SERVER['HTTP_REFERER'] == "") {
            unset($_SESSION['valid']);
            unset($_SESSION['timeout']);
            header('location:index.php');
        }
    } else {
        unset($_SESSION['valid']);
        unset($_SESSION['timeout']);
        header('location:index.php');
    }
    if (isset($_SESSION['valid'])) {
        $timeout = $_SESSION['timeout'];
        $time    = time();
        $t       = $time - $timeout;
        if ($t > 9000) { //15*60 = 900 Second, timeout to logout
            unset($_SESSION['valid']);
            unset($_SESSION['timeout']);
            header('location:index.php');
        } else {
            $_SESSION['timeout'] = time();
        }
    } else {
        header('location:index.php');
    }
    ?>
My problem is that it redirect to index.php...

It seems that the main page is not getting the session start.

If i load the two pages without the use of iframe it is working fine.

My page with the iFrame is on server A which is online host.
My pages index.php and catalogue.php are on server B which are localhost.
Post Reply