Home >Backend Development >PHP Tutorial >javascript - How does php solve the problem of displaying the content of website B's homepage on the homepage of website A?

javascript - How does php solve the problem of displaying the content of website B's homepage on the homepage of website A?

WBOY
WBOYOriginal
2016-09-13 09:00:18996browse

What should I do if I use the home page of website A to display the home page of website B?

Reply content:

What should I do if I use the home page of website A to display the home page of website B?

Use <iframe>

Currently, browsers have strict same-origin policy restrictions, so methods such as ajax cannot obtain page content across domains, and only iframes can be used.

To display all, just use iframe.
Part of the display (such as shared tail) is generally implemented using js. Two sites reference the same js at the same time.
The poster uses php, so use the following code
<script src="http:// www.b.com/index.php?source=www.a.com"></script>
B site’s index.php can be added as follows at the end:

<code>if ($_REQUEST['source']=='www.a.com'){
    $contents['data'] = ob_get_contents();
    echo sprintf("var d=%s;document.write(d.data);",json_encode($contents));
}</code>

A, are sites B yours? If so, you can use jsonp to get the content of the homepage of site B (b provides an interface). If not, you can read the content of site B in site A’s program, and then render it to HTML. And iframe

1.iframe
2.php can use the file_get_contents() function.
The premise is that all B pages are absolute links. If they are relative links, the obtained strings need to be processed again.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn