PHP如何在div dom中打开page1,重定向到page2并显示page1? [英] PHP how to open page1, redirect to page2 and show page1 in a div dom?

查看:132
本文介绍了PHP如何在div dom中打开page1,重定向到page2并显示page1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多子页面,其中的URL如www.domain.com/sub/page1.php www.domain.com/sub/page2.php ...现在,当我在浏览器中键入URL时.它们都重定向到www.domain.com/sub/index.php,并且当前子页面将显示在index.php中的一个div中.

I have many sub pages, there urls like www.domain.com/sub/page1.php www.domain.com/sub/page2.php... Now when I type there url in browser. they all redirect to www.domain.com/sub/index.php, and the current sub page will show in a div dom in the index.php.

我的知识非常有限.我只知道jqeury.loadphp header Location.但是很难重定向到index.php然后告诉index.php,这是当前的子页面,然后执行jqeury.load.

My knowledge is very limited. I only know jqeury.load and php header Location. but it is difficult redirect to index.php then tell index.php, which is the current sub-pages then do a jqeury.load.

需要注意的另一点:也应该考虑SEO. jqeury.load可能对搜索蜘蛛不利.也许应该使用hash网址.

One more note: Also should think SEO. maybe jqeury.load is bad for a search spider. maybe should use hash url.

所以我寻求帮助.有没有人可以给我一些好的建议?或简单的示例?

So I ask for a help. is there anybody could give me some good suggestion? or simple worked examples?

谢谢.

推荐答案

在每个PHP文件(例如page1.php)中,使用以下代码:

In every PHP file (e.g page1.php) use this code:

<?php
if(!defined('INCLUDE')) {
    header('Location: index.php?site=' . $_SERVER['PHP_SELF']); //Send the user to the index.php page
    die();
}
?>
Insert the content you want here...

并在index.php文件中:

<?php
define('INCLUDE', true);
if(isset($_GET['site'])) {
    $site = $_GET['site'];
} else {
    $site = 'page100.php'; //Put the name of the default page if the user visits index.php here
}
?>
<html>
<head><!-- HEAD CONTENT HERE --></head>
<body>
<div><?php 
include($site); //Put the page requested into the div
?></div>
</body>
</html>

这篇关于PHP如何在div dom中打开page1,重定向到page2并显示page1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆