iFrame - 隐藏网址和会话不起作用

Yve*_*Lee 5 php cookies iframe session session-cookies

我在不同的服务器上有两个域。第一个服务器的一个页面有一个 iframe 指向另一个服务器中的 url。我无法与 seesions 一起工作。

iFrame 页面代码(main.php):

<!DOCTYPE html>
<html>
<head>
    <base target="_parent">
</head>
<body>
    <iframe src="http://192.168.1.10/index.php"</iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

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

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

在我的 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');
}
?>
Run Code Online (Sandbox Code Playgroud)

所以我有以下几点:

           Button press                                On load it check session                 
             to log in                                 using check.php
index.php ==============> process.php ===============> catalogue.php
Run Code Online (Sandbox Code Playgroud)

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

我的问题:

  • 是每次我按下 index.php 中的按钮登录时,它都会将我重定向到 index.php 而不是 catalogue.php。
  • 我可以在 iframe 中隐藏/屏蔽 bots/spider 中的 url 吗?
  • 欢迎任何关于更好设置的建议/想法。

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

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

LIG*_*GHT 1

我认为您的会话被 阻止SameSite by default cookies

\n
\n

将未指定 SameSite 属性的 cookie 视为\nSameSite=Lax。站点必须指定 SameSite=None 才能启用\n第三方使用。\xe2\x80\x93 Mac、Windows、Linux、Chrome 操作系统、Android

\n
\n

尝试这个来检验我的理论。

\n
    \n
  1. chrome://flags/通过地址栏访问
  2. \n
  3. 寻找SameSite by default cookies
  4. \n
  5. 禁用该SameSite by default cookies 标志
  6. \n
\n