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));

  

最新文章

  1. Mvc视图的那些事
  2. Slam(即时定位与地图构建) 知识篇
  3. ubuntu mysql远程登录设置
  4. HDU 4707 DFS
  5. Java web实时进度条整个系统共用(如java上传进度条、导入excel进度条等)
  6. [CareerCup] 14.1 Private Constructor 私有构建函数
  7. javascript 变量的作用范围
  8. 分享:php 上传图片的代码
  9. Python之路【第十七篇】:Django【进阶篇】
  10. 创建ListView的基本步骤
  11. sql内置函数pivot强大的行转列功能
  12. Bundles
  13. ubuntu下MySQL修改root密码的多种方法,phpmyadmin空密码无法登陆的解决方法
  14. Docker创建Tomcat镜像
  15. 腾讯企业邮箱设置发送邮件的配置(针对smtp)
  16. VMware在Centos7上配置静态IP的方法
  17. Java反编译代码分析(一)
  18. 【LeetCode OJ】Remove Element
  19. eclipse安装Android插件
  20. 如何快速的给你的项目添加icon图标

热门文章

  1. AngularJs 常用
  2. kubernetes高级之创建只读文件系统以及只读asp.net core容器
  3. cvpr2017-code-etc
  4. anaconda的所有版本大全--下载地址
  5. 前端基础——CSS盒子模型
  6. spring 拦截器简介
  7. 前端photoshop 切图神器cutterman
  8. 异步模式模式Future(结合Callable可以获取线程返回结果)
  9. __FILE__,__LINE__,__func__ 真好用,DEBUG利器啊!
  10. struts2 session登录