三种显示防盗链图片的方法

1.file方法:

public function showimg() {

$url = $this->input->get('url', TRUE);

$pics = file($url);

for ($i = 0; $i < count($pics); $i++) {

echo $pics[$i];

}

}

调用事例:img srcc="showimg?url='http://www.dpnet.com.cn/FileServer/CuteSoftUploads/InfoImage/Business/2015/2/3/Canon-M-1.png'"/>

2.curl方法

public function showimg() {

$url = $this->input->get('url', TRUE);

$dir = pathinfo($url);

$host = $dir['dirname'];

$refer = $host . '/';

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_REFERER, $refer);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

$data = curl_exec($ch);

curl_close($ch);

$ext = strtolower(substr(strrchr($url, '.'), 1, 10));

$types = array(

'gif' => 'image/gif',

'jpeg' => 'image/jpeg',

'jpg' => 'image/jpeg',

'jpe' => 'image/jpeg',

'png' => 'image/png',

);

$type = $types[$ext] ? $types[$ext] : 'image/jpeg';

header("Content-type: " . $type);

echo $data;

}

3.iframe法

破解盗链实现代码:

window.img='window.onload = function() { parent.document.getElementById(\''+frameid+'\').height = document.getElementById(\'img\').height+\'px\'; }';

document.write('javascript:parent.img;" frameBorder="0" scrolling="no" width="100%">');

}

调用方式:

showImg('图片地址');

源地址:http://www.banghui.org/4340.html

你可能感兴趣的:(三种显示防盗链图片的方法)