Hotlink protection using OSS SDK for PHP 2.0
Use OSS SDK for PHP 2.0 to configure access control policies that rely on the Referer request header. This allows you to define a Referer whitelist, a Referer blacklist, and choose whether to allow requests with an empty Referer header. By implementing these rules, you can effectively prevent unauthorized hotlinking of your resources and reduce unnecessary data transfer costs.
Usage notes
-
Before configuring hotlink protection, make sure you understand how this feature works. For more information, see Hotlink protection.
-
The sample code in this topic uses the China (Hangzhou) region (
cn-hangzhou) as an example. By default, the public endpoint is used. If you want to access OSS from another Alibaba Cloud service in the same region, use the internal endpoint. For a full list of supported regions and endpoints, see Regions and endpoints. -
Setting or clearing hotlink protection configurations requires the
oss:PutBucketRefererpermission, while obtaining hotlink protection configurations requires theoss:GetBucketRefererpermission. For more information, see Grant custom permissions to a RAM user.
Sample code
References
-
For more information about the API operation used to set hotlink protection, see PutBucketReferer.
-
For more information about the API operation used to obtain hotlink protection configurations, see GetBucketReferer.