We’ve been using Cloudflare Images and I need to create URLs to access images created with the “requiredSignedURLs=true” flag.
Just found this library https://github.com/benbjurstrom/cloudflare-images-php/blob/main/src/CloudflareImages.php and this is basically how they do it:
$cfImageSignKey = 'YOUR_KEY_FROM_IMAGES_DASHBOARD';
$url = 'https://imagedelivery.net/cheeW4oKsx5ljh8e8BoL2A/bc27a117-9509-446b-8c69-c81bfeac0a01/mobile';
$urlPath = parse_url($url, PHP_URL_PATH);
$sig = hash_hmac('sha256', $urlPath, $cfImageSignKey);
$signedUrl = sprintf('%s?sig=%s', $url, $sig);
I have not tested yet, but it looks like it should work and is much simpler than the JS code.
Too bad this library was not available a year ago (I had to write our own).
This topic was automatically closed after 15 days. New replies are no longer allowed.