php 将外部网页加载到我的页面中而不重定向到不同的 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15866148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:05:28  来源:igfitidea点击:

Loading external webpage into my page without redirecting to different URL

phphtmlredirectiframeexternal

提问by Jordan.J.D

So what I want to do is create a subdomain on my website and have it load an external website into it without actually going to that website. For instance:

所以我想做的是在我的网站上创建一个子域,并让它加载一个外部网站,而无需实际访问该网站。例如:

google.mydomain.com loads google.com but the URL bar reads google.mydomain.com.

google.mydomain.com 加载 google.com,但 URL 栏显示 google.mydomain.com。

How do I go about doing this?

我该怎么做?

I tried thisbut could not figure it out.

我试过这个,但无法弄清楚。

Trying:

试:

iframe

内嵌框架

  1. I want page to take up the whole screen for each person's computer. Can I set it to 100% instead of x amount of pixels?

  2. I want to remove scroll bars but it says not supported.

  1. 我希望页面占据每个人计算机的整个屏幕。我可以将它设置为 100% 而不是 x 像素数量吗?

  2. 我想删除滚动条,但它说不支持。

回答by Connor Gurney

You can use either an Iframe, or file_get_contents();

您可以使用 iframe 或 file_get_contents();

Iframe:

框架:

<iframe src="http://google.com" style="width: 100%; height: 100%;">

file_get_contents():

file_get_contents():

<?php
echo file_get_contents('http://google.com');
?>

With file_get_contents(), you need to beware of the website you're fetching from using relative URL's, which will break the CSS, Images, Javascript, etc.

使用 file_get_contents(),您需要注意使用相对 URL 获取的网站,这会破坏 CSS、图像、Javascript 等。

回答by Jeffrey Blake

You are not going to be able to use php's include function, as this is not a resource residing on your server.

您将无法使用 php 的包含功能,因为这不是驻留在您服务器上的资源。

One option you could explore is loading everything in as the contents of an iframe: see http://www.w3schools.com/tags/tag_iframe.aspfor some details about the iframe html element

您可以探索的一种选择是将所有内容作为 iframe 的内容加载:有关 iframe html 元素的一些详细信息,请参阅http://www.w3schools.com/tags/tag_iframe.asp

回答by Asif Bilakhiya

  • iframe is now not supported in html5
  • it works on html5 also
  • Easy to add or remove
  • html5 现在不支持 iframe
  • 它也适用于 html5
  • 易于添加或删除

Example:

例子:

 <body onload="window.location.href='https://www.google.com/'"> </body>