Forked from krzysztofbukowski/amp-update-cache-url-generator.php
Created
February 11, 2019 16:02
-
-
Save Resurser/9719cf80c1d04cd52457bd2e89851c40 to your computer and use it in GitHub Desktop.
Amp cache url PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function urlsafe_b64encode($string) { | |
return str_replace(array('+','/','='),array('-','_',''), base64_encode($string)); | |
} | |
$timestamp=time(); | |
$ampBaseUrl = "https://www-domain-com.cdn.ampproject.org"; | |
$signatureUrl = '/update-cache/c/s/www.domain.com/amp/page-url?amp_action=flush&_ts='.$timestamp; | |
// opening the private key | |
$pkeyid = openssl_pkey_get_private("file://amp-private-key.pem"); | |
// generating the signature | |
openssl_sign($signatureUrl, $signature, $pkeyid, OPENSSL_ALGO_SHA256); | |
openssl_free_key($pkeyid); | |
// urlsafe base64 encoding | |
$signature = urlsafe_b64encode($signature); | |
// final url for updating | |
$ampUrl = $ampBaseUrl.$signatureUrl."&_url_signature=".$signature; | |
echo $ampUrl."\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment