PHP Include Full URL (or website)
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.
drewrockshard
Updated on June 04, 2022Comments
-
drewrockshard almost 2 years
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 just want to be able to include remote "websites" in the same page as my frontend.
-
Brad over 13 yearsIf this is all on your local network, then you can do your includes without an HTTP request, and reuse code simply by loading it over the network, non-HTTP. What you are doing is not just bad practice, but inefficient, unmaintainable, and insecure as well.
-
Halil Özgür over 13 yearsThis is not a very elegant solution, but would do for simple things. For something better, look at LinkedIn's iframes with Javascript.
-
Laurence Cope about 9 yearsI personally wouldn't use iframes on websites, they are no good for search engines, and its possible the iframe src can be indexed as its own webpage on Google. (I know this is a vert old thread but just found this in google for some related search so wanted to make this point)
-
Jakub Hampl about 9 years@LaurenceCope That's a pretty silly argument given that OP is talking about an intranet website which won't be indexed.
-
Laurence Cope about 9 yearsI did not originally see any reference to an "intranet" but re-reading now I can see "(all local and internal to our network)" so assuming they are not publicly accessible then should be OK. Also, if they are already indexable websites then it wont matter anyway. I had the exact issue of iframe sources being indexed on their own which I did not want (e.g. a menu sidebar). Tried removing my down vote but Stackoverflow wont let me until your answer is edited! Maybe add a statement that its OK for private pages, or already indexible pages, then I can remove my downvote and maybe upvote.