Use readfile
:
<?php readfile('http://example.com/path/with/some/variables'); ?>
题
There is a file on another site that I do not own, with a URL in the following format:
http://example.com/path/with/some/variables
I want to include this file in one of my own pages. I could use iframe
to do this, but I also want to change the CSS of something within the included file. To my knowledge, I can't do this with this method.
However, I can't seem to be able to successfully add this via PHP either, with something like:
<?php include 'http://example.com/path/with/some/variables'; ?>
I'm not sure what other methods exist that can do this, but surely this must be possible.
Also, I'm aware of the security implications of using include
in a situation like this.
解决方案
Use readfile
:
<?php readfile('http://example.com/path/with/some/variables'); ?>
其他提示
Yeah, security limitations won't allow you do do this directly in an iframe, by manipulating the DOM of the iframed file.
To do it in PHP, you could create a PHP script to read the contents of the URL and add an external CSS file that you've created, to override whatever you want. So:
myreader.php:
$contents = file_get_contents("http://example.com/path/with/some/variables");
$contents = preg_replace("/<head>/", "<head>\n<link rel='stylesheet' type='text/css' href='mystyle.css'>", $contents, 1);
echo $contents;
and then create mystyle.css:
body {
color : red !important;
}
Finally, either just point your browser to myreader.php, or if you still want it in an iframe, point the iframe src to myreader.php.
PS: Stealing is wrong :)
You can use file_get_contents
<?php $content = file_get_contents('http://example.com/path/with/some/variables'); ?>
Here is the documentation file_get_contents