Questions about access source judgment

Source: Internet
Author: User
Tags servervariables
If you have any questions about the access source, assume that my website is a.com with image a.com/123.png.

When B .com uses this image, what is http_referer?

Enter a.com/123.png http_referer in the address bar as B .com.

How can I determine whether an image is referenced by another website or accessed by a user directly?


Reply to discussion (solution)

Request. ServerVariables ["HTTP_REFERER"]
Request. ServerVariables ["HTTP_REFERER"]. ToString (). Contains (Request. ServerVariables ["HTTP_HOST"]. ToString ())

HTTP_REFERER also carries the host address of the website when the external link is in.
Add an IF statement. Then the tostring is parsed to the address, and the counter can be used to determine

Enter HTTP_REFERER in the browser as null.
From the page link, HTTP_REFERER is the url of the page

However, it should be noted that all variables with the HTTP _ prefix are provided by the access party, and the reliability is extremely low.

You can only rely on HTTP_REFERER to judge, although this is not very reliable and can be forged.

Request. ServerVariables ["HTTP_REFERER"]
Request. ServerVariables ["HTTP_REFERER"]. ToString (). Contains (Request. ServerVariables ["HTTP_HOST"]. ToString ())

HTTP_REFERER also carries the host address of the website when the external link is in.
Add an IF statement. Then the tostring is parsed to the address, and the counter can be used to determine

Is there any PHP version of hero?

$ _ SERVER ['http _ referer ']
There seems to be a lot of parameters. Let's take a look.

Leeching is the problem that the landlord said.

Header ("content-type: text/html; charset = utf-8 ");
If (isset ($ _ SERVER ['http _ referer'] [
]) {

// Determine whether $ _ SERVER ['http _ referer' starts with HTTP: // localhost/test /.
// If yes, the website is used. if not, the website is not used,
If (strpos ($ _ SERVER ['http _ referer'], "HTTP: // localhost/test/") = 0 ){
Echo 'This is a site access ';

} Else {
// Jump to the warning page
Header ('Location: warning. php ');
}

} Else {
// Jump to the warning page
Header ('Location: warning. php ');
}

The above code is a piece of anti-leeching code I wrote myself. Your problem can be solved by reading this code. This anti-leeching problem was mentioned in the 84th lecture on the php series video of Chuanzhi podcast Han Shunping. You can get to know more clearly.

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.