您现在的位置: 点击南开 >> 技术学院 >> 百度空间 >> 文章正文
 加入亚洲交友中心,与心爱的MM聊天  
百度空间图片防盗链破解程序 - PHP版
作者:佚名   文章来源:本站原创   点击数:   更新时间:2006-10-7          ★★★
载入中...
上传百度的图片无法从外部引用,让许多朋友伤透了脑筋,Verdana同学开发出了一个破解程序,可以用一段PHP代码来解决这个问题.本地清空IE 缓存后测试成功,由于没有主机,所以没有在 Internet 上面测试,有条件的朋友可以帮忙测试一下,谢谢!若有兴趣也在此程序基础上继续优化完善

以下是PHP源码.

/**
* 百度空间相册图片防盗链破解程序 - PHP版
*  
* 使用方法:  
*   
*      
* @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']);
}
?>

发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
 
  • 上一篇文章:

  • 下一篇文章:
  • 载入中...
    百度空间推荐文章
    固顶文章 [百度空间]百度空间CSS代码精选
    推荐文章 [百度空间]百度空间留言板代码
    推荐文章 [百度空间]百度空间新手教程…61.CSS鼠标
    推荐文章 [百度空间]百度空间新手教程…16.添加多
    推荐文章 [百度空间]百度空间新手教程…14.添加自
    推荐文章 [百度空间]百度空间新手教程…7.更换主体
    推荐文章 [百度空间]百度空间新手教程…4.CSS代码
    推荐文章 [百度空间]百度空间新手教程…2.百度空间
    推荐文章 [百度空间]百度空间新手教程…1.让你看懂
    推荐文章 [百度空间]百度空间最新CSS技巧归纳总结
    推荐文章 [百度空间]百度空间技巧-让你的背景,BAN
    推荐文章 [百度空间]百度空间技巧各模块添加滚动条
    推荐文章 [百度空间]百度空間--空间页面CSS说明
    推荐文章 [百度空间]百度空间里添加自己的LOGO
    推荐文章 [百度空间]百度空间技巧4-css详细说明
    百度空间热门文章
    固顶文章 [百度空间]百度空间CSS代码精选
    普通文章 [百度空间]百度空间新手教程…81.教你怎
    普通文章 [百度空间]百度空间新手教程…80.如何加
    普通文章 [百度空间]百度空间新手教程…78.百度空
    普通文章 [百度空间]百度空间新手教程…73.用CSS进
    普通文章 [百度空间]百度空间新手教程…70.教你10
    普通文章 [百度空间]百度空间新手教程…69.如何在
    普通文章 [百度空间]百度空间新手教程…67.在你的
    普通文章 [百度空间]百度空间新手教程…66.基本颜
    普通文章 [百度空间]百度空间新手教程…65.怎么去
    普通文章 [百度空间]百度空间新手教程…64.空间模
    普通文章 [百度空间]百度空间新手教程…63.为<好友
    推荐文章 [百度空间]百度空间新手教程…61.CSS鼠标
    普通文章 [百度空间]百度空间新手教程…58.背景图
    普通文章 [百度空间]百度空间新手教程…57.Iframe
    加入亚洲交友中心,与心爱的MM聊天
    相关内容
    没有相关文章
    论坛新帖
    论坛新帖载入中...
    新 闻 TOP 10
    推荐文章“我的空间我作主”个112
    - 设为首页 - 加入收藏 - 关于我们 - 网站地图 - 版权申明 - 联系我们 -

    Copyright © 2000-2006 Nkcn.Net All Rights Reserve.

    网站关键词:搜索引擎优化,SEO优化,网页特效,QQ空间技巧,QQ空间代码,百度空间技巧百度空间代码百度空间CSS代码装扮百度空间动易2006 sp5破解版动易2007破解版,个性百度空间,动易常见问题,动易采集标签,动易美化,动易模板,wap建站技巧,系统进程,动易新手帮助,网络营销,网络赚钱,QQ快讯,QQ空间模块,QQ空间大图,QQ密码找回,QQ经典贴图,QQ签名,QQ个性情侣网名,国外免费空间,国内免费空间,ASP免费空间,国外虚拟主机评测,国内虚拟主机评测,危险进程,企业信息化解决方案,,google动态,百度动态,Alexa排名,seo教程,seo工具,DMOZ技巧,网站登录,国外SEO,天津搜索引擎优化,应用程序进程,常用特效,QQ图像工具,搜索引擎常识
    津ICP备05015468号