通过FTP编辑iframe

时间:2011-04-11 22:09:33

标签: php html iframe ftp edit

我有一个加载远程页面的iframe(不托管在同一个域中)。我想编辑页面的内容,但当然,这是不可能的,因为我没有权限。

所以,我想知道,如果我有FTP访问该网站,是否会有解决问题的方法?使用FTP,我可以将网站的文件复制到我的域,并通过iframe进行编辑。但我想知道是否有另一种方法。

2 个答案:

答案 0 :(得分:0)

为什么要使用iFrame?如果您需要加载托管在另一台服务器上的页面的内容,您可以使用cURL或某些PHP文件包装器来获取其内容,例如PHP readfile函数。中提琴!

如果使用readfile(..),您还可以在显示之前对已加载的文件内容进行编辑。如果您有权限,如果您确定将从您的请求中返回有效的PHP文件,您还可以使用include()通过HTTP读取文件。

答案 1 :(得分:0)

实际上,。如果你有FTP访问该网站,你可以理论上这样做。

基本上是这样的:

// I used jQuery to speed up writing ajax code, really it could be anything else
jQuery.get('?refresh',function(){ // this function is called when the request finishes
    // force the iframe to do a complete refresh (hence the random token)
    jQuery('#iframe').attr('src','http://targetsite.com/somefile.php?r='+Math.random());
});

// if the variable in question was set...
if(isset($_REQUEST['refresh'])){
    // the following requires "allow_url_fopen" config to be on
    // otherwise, you could use any other PHP FTP library
    file_put_contents('ftp://username:password@targetsite.com/somefile.php','Hello');
}