Sign URI (PHP REST)

Skip to end of metadata
Go to start of metadata
This example allows you to sign a URI using Saaspose REST API in PHP.
    public static function Sign($UrlToSign) {
        // parse the url
        $url = parse_url($UrlToSign);
      
        if (isset($url['query']) == "")
            $urlPartToSign = $url['path'] . "?appSID=" . SaasposeApp::$AppSID;
        else
            $urlPartToSign = $url['path'] . "?" . $url["query"] . "&appSID=" . SaasposeApp::$AppSID;
 
        // Decode the private key into its binary format
        $decodedKey = self::decodeBase64UrlSafe(SaasposeApp::$AppKey);

        // Create a signature using the private key and the URL-encoded
        // string using HMAC SHA1. This signature will be binary.
        $signature = hash_hmac("sha1", $urlPartToSign, $decodedKey, true);

        $encodedSignature = self::encodeBase64UrlSafe($signature);

        // return $UrlToSign . "?appSID=" . $this->APPSID . "&signature=" . $encodedSignature;
        if (isset($url['query']) == "")
            return $url["scheme"] . "://" . $url["host"] . str_replace(" ","%20",$url["path"]) . "?appSID=" . SaasposeApp::$AppSID . "&signature=" . $encodedSignature;
        else
            return $url["scheme"] . "://" . $url["host"] . str_replace(" ","%20",$url["path"]) . "?" . $url["query"] . "&appSID=" . SaasposeApp::$AppSID . "&signature=" . $encodedSignature;
    }
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.