1

I was wondering if anyone know how to achieve this.

I have an index.php that loads a file page.php into a div using jQuery. This page.php has a link that when you click it loads page2.php into the same div(so the url always stays as index.php).

I want to make it so that, if you open the link on page.php in a new tab or window, instead of loading page2.php, it loads index.php(with page.php in the div). Same if you type in the link to page2.php directly into the browser.

4

3 回答 3

0

使用会话。

在第 1 页:

session_start();
$_SESSION['beenhere'] = 1;

在第 2 页

session_start();
if(!isset($_SESSION['beenhere'])){
    header('./index.php');
}
//rest of page....
于 2013-05-07T19:09:43.787 回答
0

这是“在新标签页中打开”部分

索引.php

<a href="index.php" onclick="javascript:$('#myDiv').load('page2.php');return false;">Link</a>
<div id="myDiv"></div>

如果用户写入页面的直接链接也可以使其正常工作,只需检查 page2 是否有引用者,如果不只是将他发送到 index.php

page2.php

if ($_SERVER['HTTP_REFERER']!="index.php"){
    header("Location: http://www.example.com/index.php");
}
于 2013-05-07T19:45:44.490 回答
-2

在 index.php 上设置一个全局变量,如果加载 page.php 时它不存在,则重定向到 index.php。

于 2013-05-07T19:07:55.027 回答