PHP镜像一个网页 [英] PHP mirror a webpage

查看:387
本文介绍了PHP镜像一个网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用于网站的天气小部件的镜像。目前,它在HTTPS页面上使用,但是小部件服务器不支持它(并且IE引发了对话框,因为小部件不是HTTPS)

I am trying to create a mirror of a weather widget which I use for a website. Presently, it is used on an HTTPS page, but widget server does not support that (and IE throws a tantrum with dialogs because the widget is not HTTPS)

要解决这个问题,我想做的是在HTTPS中镜像页面以消除安全警告。我通常会使用 file_get_contents(),但页面包含的图片会使它更复杂。

To solve this, I would like to do is mirror the page in HTTPS to silence the security warnings. I would normally use file_get_contents() for this, however the page contains images which makes it a little more complicated.

**另外作为旁注,我的网站上没有任何广告,因此没有收入窃取

**Also as a side note, there isn't any ads on my website or theirs, so there is no revenue stealing

推荐答案

使用CURL抓取页面的内容(图像和所有内容)。您可以将其放在一个文件中,然后使用该URL代替您使用窗口小部件URL的位置:

Use CURL to grab a page's content (images and all). You can put this in a file, then use that URL in place of where you'd use the widget's URL:

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

查看文档: http://www.php.net/manual/en/function.curl-exec.php

这篇关于PHP镜像一个网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆