PHP analog reffer hack to prevent stolen images

Source: Internet
Author: User

When we need to call other site pictures, other site pictures often show a not displayed, but in a separate browser access, but it can.

Php

Simulate Reffer hack to prevent stolen images

<?php
error_reporting (0);

$HOST = "java-er.com";


Require ' class/db.php ';
Header ("Content-type:image/png");

$id = $_get["id"];
$sql = "SELECT * from blog where id= $id";
$row = $db->queryrow ($sql);
$url = $row ["url"];
The read out URL for http://www.sina.com.cn/aaad.html will act as a reffer

$imgurl = $_get["url"];

Extract image Domain
$domain = Preg_replace ("/^http:\/\/" (. +?) \/.+?$/"," $ ", $imgurl);

Compatible with the original site like/2.jpg
if ($url = = "") {
$url = $imgurl;
}

if (!preg_match ("/^http:\/\/.*?$/", $imgurl)) {
$domain = $HOST;
$imgurl = "http://". $HOST. " /". $imgurl;
$url = $imgurl;
}


Compatible with the original web end




image.58.com/showphone.aspx?t=v55&v=0926dc20fe0c323bh29559c838d7cb65e

$fp = Fsockopen ("$domain", $errno, $errstr, 30);
if (! $fp) {
echo "ERR: $errstr ($errno) <br/>\n";
} else {
$out = "Get $imgurl http/1.1\r\n";
$out = "get/http/1.1\r\n";
$out. = "accept:*/*\r\n";
$out. = "Host: $domain \ r \ n";
$out. = "Referer: $url \ r \ n";
$out. = "connection:close\r\n\r\n";
$str = "";
Fwrite ($fp, $out);
while (!feof ($fp)) {
$str. =fgets ($FP, 128);
}
$str = Trimheader ($STR);
Echo $str;
Fclose ($FP);
}


function Trimheader ($content) {
$array =split ("\r\n\r\n", $content);
return $array [1];
}

?>
Automatically replace your Web page when you enter the contents of a picture

$c = Preg_replace ("//is", "If you are a technician can add me QQ 2651-0442-02, if you are Java technology people can also join QQ group 1784-9136-0

Starting address: Monthly Small Rise blog-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.