PHP Include Full URL (or website)
I'm trying to do something that I thought was simple but doesn't appear to be so.
What I'm wanting is to be able to include a separate website in my PHP code. Basically, the reason for this is that I'm writing a "main" page that has links on it, and below my links are the "included" websites in the same page. Reasoning is, I'm just building a simple "main" place for all my users to get to our tools. The problem is, our tools are spanned out across several other websites (all local and internal to our network). In PHP, I'm not sure you can do this, and the way to "do this" would be to get the contents of the remote site using file_get_contents()
:
<?php
$a = file_get_contents("http://url/folder");
echo ($a);
?>
The problem with this solution is that all the includes and references to CSS files are now all broken, because, I believe, with file_get_contents()
it just brings over the source that would have been generated, so links CSS code will be lost and it will inherit the CSS that the current page uses.
It's almost like I want this to work as if it were like an iframe, but I don't want to use iframes, I j开发者_Go百科ust want to be able to include remote "websites" in the same page as my frontend.
Well generally a solution would be to parse the source code and fix the links yourself. Although I'd still have a tendency to use iframes - that's what they're useful for.
I was actually able to figure this out myself. While it's not good PHP practice/security, I enabled allow_url_include
in php.ini and this resolved things. Again, this may be back practice, however, the included URLs are simple websites/URLs internal to our organization, and is also not accessible outside of our network.
you would have to rewrite al the other pages to have absolute links to all their included resources [css,js,etc] other than that, you can di iframes pretty transparently, check out http://api.fatherstorm.com/test/ where I do some jQuery magic to append pages on click events without you being able to tell they're in iframes.
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Description" name="Description" content="">
<meta http-equiv="Keywords" name="Keywords" content="">
<TITLE>Title</TITLE>
</HEAD>
<FRAMESET rows="*,0">
<FRAME src="http://url/folder" frameborder="0" noresize>
<NOFRAMES>
Your browser does not support frames.
</NOFRAMES>
</FRAMESET>
</HTML>
精彩评论