显示另一页的内容而不更改网址

时间:2013-10-16 04:52:46

标签: php

我已经有像

这样的网页了
http://example.com/page1
http://example.com/page2
http://example.com/page3

我需要在以下子域

上加载这些页面
http://page1.example.com/
http://page2.example.com/
http://page3.example.com/

它应该有效http://page1.example.com/应加载http://example.com/page1的内容而不更改浏览器地址栏中的网址

我使用了以下代码,但它更改了浏览器地址栏中的网址

header('Location: http://example.com/page1'); 

请帮助。

2 个答案:

答案 0 :(得分:0)

试试这个。这是一种黑客攻击:

// Just add the below few lines of code in your subdomain page - http://page1.example.com/
<?php
$content = file_get_contents('http://example.com/page1');
echo $content;
?>

请告诉我这是否适合您。

答案 1 :(得分:0)

<?php
include 'http://example.com/page1';
?>

这将导入页面的所有内容。如果有多次调用session_start(),您也可以使用“include_once”而不是“include”。

类似地,

<?php
require 'http://example.com/page1';
?>
如果找不到文件,

“require”会停止加载页面的其余部分,而“include”不会停止。