如果考虑突破防盗链的措施,就需要考虑在 HTTP_REFERER 上面做手脚了。很多网站是通过referer来判断是否盗链。
那么如果考虑突破防盗链的措施,就需要考虑在 HTTP_REFERER 上面做手脚了。PHP 脚本中对应的变量是 $_SERVER['HTTP_REFERER'] ,它存储了 HTTP_REFERER 的值。
由于直接访问目标 URL 资源已经被上述防盗链的措施给屏蔽,所以我们需要个类似网关的玩意去获取。说白了就是编写已经包装过的 HTTP 头的 PHP 脚本。
下面是简单的函数实现:
代码如下:
function getRemoteFile($url, $refer = '') {
$option = array(
'http' => array(
'header' => "Referer:$refer")
);
$context = stream_context_create($option);
return file_get_contents($url, false, $context);
}
这是个比较简单的函数,其功能就是伪造 Referer (使用 )然后获取对方的数据(使用 file_get_contents,需要开启 )。
如果想“复杂”一点,可以使用 ,这不在这里的讨论范围以内。
另外,再提供个获取主机名的正则函数
代码如下:
function getHost($url) {
$result = preg_match('/^http:\/\/([\d|\w|\.]+)\//', $url, $matches);
if (sizeof($matches) >= 2) {
return $matches[1];
} else {
return null;
}
}
再进一步的扩展,可以封装成脚本,然后譬如调用
http://127.0.0.1/proxy.php?url=http://i.am/img就可以获取那些开启防盗链措施的链接了(再发挥下,使用 Javascript 将图片链接全部替换)。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
