duanjia3187 2011-06-07 09:47
浏览 78
已采纳

PHP如何打开page1,重定向到page2并在div dom中显示page1?

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.

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.

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?

Thanks.

  • 写回答

1条回答 默认 最新

  • dpxf81245 2011-06-07 11:52
    关注

    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...
    

    And in the index.php file:

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算