Configure bucket-level access control policies based on the Referer request header using OSS SDK for PHP 2.0. Define a Referer whitelist, a Referer blacklist, and the behavior for requests with an empty Referer header to block unauthorized hotlinking and reduce unnecessary data transfer costs.
Prerequisites
Before you begin, ensure that you have:
An OSS bucket
The
oss:PutBucketRefererpermission to set or clear hotlink protection configurationsThe
oss:GetBucketRefererpermission to retrieve hotlink protection configurationsOSS SDK for PHP 2.0 installed (
vendor/autoload.phpavailable)AccessKey ID and AccessKey secret stored as environment variables
For information about granting permissions to a RAM user, see Grant custom permissions to a RAM user.
Usage notes
Review how hotlink protection works before configuring it. See Hotlink protection.
The examples use the China (Hangzhou) region (
cn-hangzhou) with a public endpoint. To access OSS from another Alibaba Cloud service in the same region, specify the internal endpoint. For all supported regions and endpoints, see Regions and endpoints.