PHP code for authentication of three types of authentication: CDNa, B, and c
A authentication method code
// Http: // DomainName/Filename? Auth_key = timestamp-rand-uid-md5hash
// Sstring = "URI-Timestamp-rand-uid-PrivateKey" (URI is the relative address of the user's request object, such as/Filename)
// HashValue = md5sum (sstring)
Function PrivateKeyA (){
$ Time = strtotime ("+ 8 hours ");
$ Key = "youkey ";
$ Domain = "http://www.a.com ";
$ Filename = "/mulu/1.jpg ";
// $ Sstring = "URI-Timestamp-rand-uid-PrivateKey"
$ Sstring = $ filename. "-". $ time. "-0-0-". $ key;
$ Md5 = md5 ($ sstring );
$ Auth_key = "auth_key =". $ time. "-0-0-". $ md5;
$ Url = $ domain. $ filename ."? ". $ Auth_key;
Echo $ url. "\ n ";
}
B authentication code
// Http: // DomainName/timestamp/md5hash/FileName
// Timestamp: the time when the user accesses the client source server, which is part of the URL and a factor used to calculate the md5hash. the format is YYYYMMDDHHMM and the validity period is 1800 s.
// Md5hash: uses timestamp, FileName, and preset PrivateKey as the MD5 string, that is, md5 (PrivateKey + timestamp + FileName)
Function PrivateKeyB (){
$ Time = date ("YmdHi ");
$ Key = "youkey ";
$ Domain = "http://www.a.com /";
$ Filename = "/mulu/1.jpg ";
// $ Sstring = "PrivateKeytimestampFileName"
$ Sstring = $ key. $ time. $ filename;
$ Md5 = md5 ($ sstring );
$ Url = $ domain. $ time. "/". $ md5. $ filename;
Echo $ url. "\ n ";
}
C authentication code:
// Http: // DomainName/{/}/FileName
// Md5hash = md5sum ()
// Time: The time when the user accesses the source server. the UNIX time is represented by a hexadecimal number.
Function PrivateKeyC (){
$ Time2 = dechex (time ());
$ Key = "youkey ";
$ Domain = "http://ww.a.com /";
$ Filename = "/mulu/1.jpg ";
// $ Sstring = PrivateKeyFileNametime
$ Sstring = $ key. $ filename. $ time2;
$ Md5 = md5 ($ sstring );
$ Url = $ domain. $ md5. "/". $ time2. $ filename;
Echo $ url. "\ n ";
}
403 is returned for all authentication errors.
Md5 calculation error:
X-Tengine-Error: denied by req auth: invalid md5hash = de7bfdc915ced05e171_a149bd760be
Time error:
X-Tengine-Error: denied by req auth: expired timestamp = 1439469547