|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
您现在的位置: ChinaBeta.cn 中文IT资讯 >> 网盟学院 >> 网站设计 >> 网管技术正文
推荐网管技术让我穿过那道"墙"! 畅游网络应…推荐网管技术主动防御!瑞星杀毒2008抢先评…
推荐网管技术速度超快 Discuz! 6.0.0试用手…推荐网管技术奇虎举证:各杀毒软件均报CNNIC…
推荐网管技术Google Earth 4.2加入繁体中文…推荐网管技术专业防护!瑞星防火墙2008测试…
推荐网管技术挂载RAR文件 从认识到爱上WinM…推荐网管技术让你冲浪随心所欲 如何访问被封…
推荐网管技术轻装上阵!江民杀毒软件2008速…推荐网管技术VMware Fusion苹果版全程图解(…
推荐网管技术VMware Fusion苹果版全程图解(…推荐网管技术从菜鸟出发!征服高清详细评测全…
推荐网管技术VS2008和ASP.NET 3.5使用之初体…推荐网管技术[多图]Ubuntu 7.04 初体验
推荐网管技术东风吹战鼓擂 下载软件你选谁?推荐网管技术若隐若现 Windows XP DirectX …
推荐网管技术GPRS上网全攻略推荐网管技术主流杀毒软件Vista兼容性横评
推荐网管技术基于IRF的网络管理和业务管理解…推荐网管技术83个美丽的Wordpress主题
推荐网管技术软交换网络中的关键路由技术详…推荐网管技术不只是换肤?Windows Mobile 6 …
推荐网管技术css教程–十步学会用css建站(全…推荐网管技术巧妙设置路由 预防网络频繁掉线
推荐网管技术打造网络管理七大绝技推荐网管技术CorelDRAW X3 Service Pack 2 …
推荐网管技术重温经典:回归 Live Messenger…推荐网管技术Oracle数据库补丁分类、安装及…
百度空间图片防盗链破解程序 - PHP版
Www.ChinaBeta.Cn 更新时间:2006-7-17 阅读次数:

【ChinaBeta.Cn 网盟学院】
上传百度的图片无法从外部引用,让许多朋友伤透了脑筋,Verdana同学开发出了一个破解程序,可以用一段PHP代码来解决这个问题.本地清空IE 缓存后测试成功,由于没有主机,所以没有在 Internet 上面测试,有条件的朋友可以帮忙测试一下,谢谢!若有兴趣也在此程序基础上继续优化完善 :)

以下是PHP源码.


/**
 * 百度空间相册图片防盗链破解程序 - PHP版 
 * 
 * 使用方法: 
 *  
 *      http://yourdomain/frivoller.php?url=http://hiphotos.baidu.com/verdana/pic/item/baidupicture.jpg
 *
 * @author  verdana
 * @version 1.0
 * @since   July 16, 2006
 */
Class Frivoller
{
    /**
     * The HTTP Version (1.0, 1.1) , Baidu use version 1.1
     *
     * @var string
     */
    protected $version;

    /**
     * The HTTP response body
     * 
     * @var string
     */
    protected $body;
    
    /**
     * The HTTP URL
     * 
     * @var string
     */
    protected $link;

    /**
     * An array that containing any of the various components of the URL. 
     *
     * @var array
     */
    protected $components;

    /**
     * The HTTP host
     *
     * @var string
     */
    protected $host;

    /**
     * The path of required file.
     * (e.g. '/verdana/abpic/item/mygirl.png')
     *
     * @var string
     */
    protected $path;

    /**
     * The HTTP referer, extra it from original URL
     *
     * @var string
     */
    protected $referer;

    /**
     * The HTTP method, 'GET' for default
     *
     * @var string
     */
    protected $method   = 'GET';

    /** 
     * The HTTP port, 80 for default
     * 
     * @var int
     */
    protected $port     = 80;

    /**
     * Timeout period on a stream
     * 
     * @var int
     */
    protected $timeout  = 100;

    /**
     * The filename of image
     *
     * @var string
     */
    protected $filename;

    /**
     * The ContentType of image file.
     * image/jpeg, image/gif, image/png, image
     * 
     * @var string
     */
    protected $contentType;


    /**
     * Frivoller constructor
     *
     * @param string $link
     */
    public function __construct($link)
    {
        // parse the http link
        $this->parseLink($link);

        // begin to fetch the image
        $stream = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
        if (!$stream) die ("ERROR: $errno - $errstrn");

        fputs($stream, $this->buildHeaders());

        $this->body = "";
        while (!feof($stream)) {
            $this->body .= fgets($stream, 4096);
        }

        // extract picture data
        $this->extractBody($this->body);      

        // send 'ContentType' header for saving this file correctly
        // 如果不发送CT,则在试图保存图片时,IE7 会发生错误 (800700de)
        // Flock, Firefox 则没有这个问题,Opera 没有测试
        header("Content-Type: $this->contentType");

        print $this->body;      

        // save this picture
        // file_put_contents('hello.jpg', $this->body);

        fclose($stream);
    }


    /**
     * Compose HTTP request header
     * 
     * @return string 
     */
    private function buildHeaders()
    {
        $request  = "$this->method $this->path HTTP/1.1rn";
        $request .= "Host: $this->hostrn";
        $request .= "Content-Type: image/jpegrn";
        $request .= "Accept: */*rn";
        $request .= "Keep-Alive: 300rn";
        $request .= "Connection: closern";
        $request .= "Referer: $this->refererrn";
        $request .= "Cache-Control: max-age=315360000rnrn";

        return $request;
    }


    /**
     * Strip initial header and filesize info
     */
    private function extractBody(&$body)
    {     
        // The status of link
        if(strpos($body, '200 OK') > 0) {

            // strip header
            $endpos = strpos($body, "rnrn");
            $body = substr($body, $endpos + 4);

            // strip filesize at nextline
            $body = substr($body, strpos($body, "rn") + 2);
        }        
    }


    /**
     * Extra the http url
     * 
     * @param $link
     */
    private function parseLink($link)
    {
        $this->link         = $link;
        $this->components   = parse_url($this->link);
        $this->host         = $this->components['host'];
        $this->path         = $this->components['path'];
        $this->referer      = $this->components['scheme'] . '://' . $this->components['host'];
        $this->filename     = basename($this->path);
        
        // extract the content type
        $ext = substr(strrchr($this->path, '.'), 1);
        if ($ext == 'jpg' or $ext == 'jpeg') {
            $this->contentType  = 'image/pjpeg';
        }
        elseif ($ext == 'gif') {
            $this->contentType  = 'image/gif';
        }
        elseif ($ext == 'png') {
            $this->contentType  = 'image/x-png';
        }
        elseif ($ext == 'bmp') {
            $this->contentType  = 'image/bmp';
        }
        else {
            $this->contentType  = 'application/octet-stream';
        }
    }
}


// Get the url, maybe you should check the given url
if (isset($_GET['url']) and $_GET['url'] != '') {
    new Frivoller($_GET['url']);
}
?>
 
  相关的链接
· 更多相关的 百度新闻主题
· 新闻来源为 ugmbbc


最受欢迎的报导,关于 百度新闻主题:
有关百度空间域名抢注,live帐号后的又一股旋风

  文章评分
平均分数: 4
票数: 1


请花一秒钟给这篇文章一个分数:

完美
非常好
好
一般
差

  选项

 友善打印格式 友善打印格式

Google

(责任编辑:hahack)

发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
热门文章 相关报道
普通网管技术 [软件应用]凤凰涅槃 驱动精灵2008归来 (01-03)最新网管技术
普通网管技术 [ASP|ASP.NET]为ASP.NET MVC框架添加AJAX支持 (01-02)最新网管技术
普通网管技术 [JSP|JAVA]从Java到Ruby:献给引路人的策略 (01-02)最新网管技术
普通网管技术 [PHP]PHP多文件上传实例 (01-02)最新网管技术
普通网管技术 [其它编程程序]QQ 静态截图完善实现之改造 CRec… (01-02)最新网管技术
普通网管技术 [其它编程程序]C++运算符重载转换运算符 (01-02)最新网管技术
普通网管技术 [其它编程程序]详细解析C++编写的ATM自动取款机… (01-02)最新网管技术
普通网管技术 [其它编程程序]C++中用vectors改进内存的再分配 (01-02)最新网管技术
普通网管技术 [其它编程程序]C++中的虚函数((((virtual funct… (01-02)最新网管技术
普通网管技术 [其它编程程序]C++中用函数模板实现和优化抽象操… (01-02)最新网管技术
  • 跟我一起玩百度空间+CSS教程…

  • 新闻与软件集装:百度空间,空…

  • 技术文章:在百度空间使用HT…

  •   网友评论内容:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    I D *
    邮 箱
    主 页
    评 分 1分 2分 3分 4分 5分
    评 论

    关于我们  中国·国家信息产业部{粤ICP备06006652号}{陇ICP备06002562号}
    版权所有:『AK网盟基地』站长:Hahack | QQ:80505955 | E-mail:Hahack@Gmail.com
    Copyright (C) 2005-2007  akhack.org|chinabeta.cn All Rights Reserved