代码之家  ›  专栏  ›  技术社区  ›  YvetteLee

无法在iframe上启动会话?

  •  0
  • YvetteLee  · 技术社区  · 5 年前

    我在不同的服务器上有两个域。第一个服务器的一个页面有一个iframe指向另一个服务器中的url。我无法应付这种情况。

    iFrame页面代码(main.php):

    <!DOCTYPE html>
    <html>
    <head>
        <base target="_parent">
    </head>
    <body>
        <iframe src="http://192.168.1.10/index.php"</iframe>
    </body>
    </html>
    

    我的iFrame页面index.php有一个启动会话的简单登录系统。因此,有一个按钮可以加载以下代码(process.php):

    <?php
    session_start();
    $_SESSION['valid'] = true;
    $_SESSION['timeout'] = time();
    header('location:catalogue.php');
    ?>
    

    在我的catalogue.php和每个页面上,我都有以下会话代码(check.php):

    <?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');
    }
    ?>
    

    所以我有以下几点:

               Button press                                On load it check session                 
                 to log in                                 using check.php
    index.php ==============> process.php ===============> catalogue.php
    

    我使用iframe来隐藏我的网络应用程序的真实网址和更用户友好的域名。

    我的问题:

    • 每次我按下index.php中的按钮登录时,它都会将我重定向到index.php,而不是catalogue.php。
    • 我可以在iframe中隐藏/屏蔽url以防止机器人/蜘蛛攻击吗。
    • 欢迎对更好的设置提出任何建议/想法。

    **更新** 经过一些测试,我认为会话没有开始(check.php)。它将会 else 在底部。我有公共服务器和本地服务器。

    这个 main.php 没有任何会话代码。 只有iframe中的页面有。 这个 index.php 没有。如果用户按登录以加载 process.php (启动会话)并重定向到 catalogue.php . Catalogue.php 我的应用程序的所有页面都有一个代码( check.php )用于检查会话。

    0 回复  |  直到 5 年前
        1
  •  1
  •   LIGHT    5 年前

    我想你的会话被阻止了 SameSite by default cookies .

    将未指定SameSite属性的Cookie视为 SameSite=Lax。站点必须指定SameSite=None才能启用 第三方使用。Mac、Windows、Linux、Chrome OS、Android

    请尝试验证我的理论。

    1. 首选 chrome://flags/ 通过您的地址栏
    2. 查找 SameSite默认Cookie
    3. 禁用 SameSite默认Cookie 旗帜