php破解防盗链技术

发送http请求

构造referer信息

在Http协议中,头信息里,有一个重要的选项: Referer

Referer: 代表网页的来源,即上一页的地址

具体方法http.class.php

// http请求类的接口
interface Proto {
// 连接url
function conn($url); //发送get查询
function get(); // 发送post查询
function post(); // 关闭连接
function close();
} class Http implements Proto { const CRLF = "\r\n"; protected $errno = -1;
protected $errstr = '';
protected $response = ''; protected $url = null;
protected $version = 'HTTP/1.1';
protected $fh = null; protected $line = array();
protected $header = array();
protected $body = array(); public function __construct($url) {
$this->conn($url);
$this->setHeader('Host: ' . $this->url['host']);
} // 此方法负责写请求行
protected function setLine($method) {
$this->line[0] = $method . ' ' . $this->url['path'] . '?' .$this->url['query'] . ' '. $this->version;
} // 此方法负责写头信息
public function setHeader($headerline) {
$this->header[] = $headerline;
} // 此方法负责写主体信息
protected function setBody($body) {
$this->body[] = http_build_query($body);
} // 连接url
public function conn($url) {
$this->url = parse_url($url);
// 判断端口
if(!isset($this->url['port'])) {
$this->url['port'] = 80;
} // 判断query
if(!isset($this->url['query'])) {
$this->url['query'] = '';
} $this->fh = fsockopen($this->url['host'],$this->url['port'],$this->errno,$this->errstr,3);
} //构造get请求的数据
public function get() {
$this->setLine('GET');
$this->request();
return $this->response;
} // 构造post查询的数据
public function post($body = array()) {
$this->setLine('POST'); // 设计content-type
$this->setHeader('Content-type: application/x-www-form-urlencoded'); // 设计主体信息,比GET不一样的地方
$this->setBody($body); // 计算content-length
$this->setHeader('Content-length: ' . strlen($this->body[0])); $this->request(); return $this->response;
} // 真正请求
public function request() {
// 把请求行,头信息,实体信息 放在一个数组里,便于拼接
$req = array_merge($this->line,$this->header,array(''),$this->body,array(''));
//print_r($req); $req = implode(self::CRLF,$req);
//echo $req; exit; fwrite($this->fh,$req); while(!feof($this->fh)) {
$this->response .= fread($this->fh,1024);
} $this->close(); // 关闭连接
} // 关闭连接
public function close() {
fclose($this->fh);
} } $http = new Http('http://localhost/apple.jpg'); //本机服务器www目录下的apple.jpg图片 $http->setHeader('Referer: http://localhost'); //构造Referer信息
$res = $http->get();
//print_r($res);
file_put_contents('./aa.png',substr(strstr($res,"\r\n\r\n"),4));

  

php破解防盗链技术的更多相关文章

  1. php笔记05:http协议中防盗链技术

    倘若我们自己在电脑上写了一个网站文件(可以是html,php文件等等),但是只希望本机可以访问这个文件,不希望别的电脑访问就需要这里的防盗链技术 1.我们在本地写了一个import.php文件: 而且 ...

  2. 防盗链技术终极解决方案(squid+cookie)

    防盗链技术现状:1.通过识别Referer确认请求来源页面2.Apache,squid等都能对Referer进行识别3.通过ActiveX显示的内容不向服务器提供Referer Header(例如,F ...

  3. php防盗链技术

    在Http协议中,头信息里,有一个重要的选项: Referer Referer: 代表网页的来源,即上一页的地址 如果是直接在浏览器上输入地址,回来进来,则没有Referer头. 这也是: 为什么服务 ...

  4. http协议以及防盗链技术

    http协议,又称为超文本传输协议,顾名思义,http协议不仅能传输文本,还能传输图片,视频,压缩包等文件,http协议是建立在tcp/ip协议的基础之上的,http协议对php程序员来讲可以说是重中 ...

  5. [php]referer应用--http防盗链技术

    1.防盗链的理解 所谓防盗链是防止其他的网站引用自己网站的资源连接,比如图片.视频等等,但是并不会阻碍从自己网站上享受资源的用户,这就要求能够将其他网站的连接请求阻止 2.防盗链的原理 其实从自己网站 ...

  6. JavaWeb学习记录(二)——防盗链技术

    public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpSer ...

  7. php curl破解防盗链

    function get_content($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $header = array( ...

  8. Java破解图片防盗链

    前言 今天想下载几张好看的壁纸,然后发现了一张是自己比较喜欢的额.然后点进去看看,WOW!好多好看的壁纸呀,于是我就起了贪念.哈哈!想把他们这一组图片打包下载,小白的方法就是一张一张下载,那样对于我们 ...

  9. 网站资源被盗链的:预防方法 VS 网站资源防盗链的:破解技巧

    1 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问! 1 资源被盗链:(简明定义) 下载者不是从你的网站直接下载资源,而是通过其他盗链网站提供的你的下载资源链接进行下载你的服务 ...

随机推荐

  1. Django-content—type

    Django包含一个contenttype应用,它可以追踪安装在你的Django项目里的所有的应用,并提供一个高层次的,通用的接口用于与你的模型进行交互 Contenttypes 的核心应用是Cont ...

  2. lowB三人组代码示例

    冒泡排序:列表在内存重只存一份,所以不需要重复赋值 import random from timewrap import * #时间装饰器 # 初级版本 @cal_time def bubble_so ...

  3. 转载---- 使用opencv源码自己编制android so库的过程

    http://blog.csdn.net/lantishua/article/details/21182965 工作需要,在Android上使用OpenCV.opencv当前的版本(2.4.8)已经有 ...

  4. Ajax技术实现页面无刷新跳转

    Ajax实现无刷新显示新的页面 <!DOCTYPE html> <html> <head> <script src="/jquery/jquery- ...

  5. 02 php生成xml数据

    <?php class Response_xml{ /** *按xml方式输出通信 *@param integet $code 状态码 *@param string $message 提示信息 ...

  6. 多媒体开发之---h.264 SPS PPS解析源代码,C实现一以及nal分析器

    http://blog.csdn.net/mantis_1984/article/details/9465909 http://blog.csdn.net/arau_sh/article/detail ...

  7. httpurlconnection模拟post提交form表单(普通文本和上传文件) (

    http://blog.sina.com.cn/s/blog_8417657f0101gvpc.html 用HttpUrlConnection模拟post表单进行文件上传平时很少使用,比较麻烦. 原理 ...

  8. jquery动态加载脚本

    如果你使用的是jQuery,它里面有一个内置的方法可以用来加载单个JS文件.当你需要延迟加载一些js插件或其它类型的文件时,可以使用这个方法. 一.jQuery getScript()方法加载java ...

  9. spring mvc 设置设置默认首页的方式

    背景: 项目使用springmvc管理请求,有一个小的需求,输入域名的时候自动进入某个页面(或者说自动发起某个请求). 过程: 1,首先想到 在web.xml中配置welcome-file-list的 ...

  10. android DownloadManager.getInputStream返回null的一种情况

    将下载操作的代码放到一个新的子线程中来执行.