How can I create a signed image link (without Javascript)

How can I create a signed image link without using Javascript?

We’ve been using Cloudflare Images and I need to create URLs to access images created with the “requiredSignedURLs=true” flag.

All the examples I’ve been able to find seem to use Javascript and don’t show how to do it in any other languages. In this particular case, I need to do it in PHP.

Just found this library and this is basically how they do it:

$url = '';
$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.