PHP code for authentication of three types of authentication: CDNa, B, and c

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.