Home >Backend Development >PHP Tutorial >Break through the anti-leeching measures based on HTTP_REFERER in PHP (stream_context_create)_PHP tutorial
So if you consider taking measures to prevent hotlinking, you need to consider manipulating HTTP_REFERER. The corresponding variable in the PHP script is $_SERVER['HTTP_REFERER'], which stores the value of HTTP_REFERER.
Since direct access to the target URL resource has been blocked by the above anti-hotlinking measures, we need something similar to a gateway to obtain it. To put it bluntly, it is to write a PHP script that has wrapped HTTP headers.
The following is a simple function implementation:
This is a relatively simple function. Its function is to forge the Referer (using the stream_context_create function) and then obtain the other party's data (using file_get_contents, you need to enable allow_url_fopen).
If you want to be more "complex", you can use sockets extension, which is beyond the scope of discussion here.
In addition, provide a regular function to get the host name