PHP Output English Time Date security method (RFC 1123 format) _php Tutorial

Source: Internet
Author: User
Tags rfc
The most recent project is to write a client for a rest service, where the signature check needs to generate a date in RFC 1123 format in the HTTP header.

This problem is better solved, simply flip through the PHP document, using Gmstrftime This function can be solved.
Copy CodeThe code is as follows:
String Gmstrftime (string $format [, int $timestamp = time ()])
The code for the call is as follows:
Copy CodeThe code is as follows:
Echo Gmstrftime ("%a,%d%b%Y%T%Z", Time ());
Output: Tue, APR 16:16:07 GMT
During the commissioning process, it was found that on another computer, the output was not as expected, and then produced the Chinese:
Copy CodeThe code is as follows:
Two, 4 16:20:02 GMT
Continue to page through the document, find the note in the document, the result of this function is affected by the setlocale result, both the current system default language. Use the following command to view the languages that are currently installed on your system:
Copy CodeThe code is as follows:
Locale-a
Then, based on the results of the analysis just now, it is no problem to force the setlocale to be specified as English, the code is as follows:
Copy CodeThe code is as follows:
SetLocale (lc_time, ' en_US ');
Echo Gmstrftime ("%a,%d%b%Y%T%Z", Time ());
This article should have ended, but unfortunately the test used on the Ubuntu machine, because it is live CD version, there is no en_us the language, but there is a en_us. UTF-8. This time the psychological drum, this practice seems not very safe, I can not determine whether to run the code on the client, whether there is en_US or en_US. UTF-8. Fortunately see a section of the document comments, can be replaced with gmdate, the function is not affected by the setlocale result:
Copy CodeThe code is as follows:
Gmdate (' d, D M Y h:i:s '). ' GMT ';
Case closed~ Demand is small, it is not easy to write well, after more efforts.

http://www.bkjia.com/PHPjc/802222.html www.bkjia.com true http://www.bkjia.com/PHPjc/802222.html techarticle The most recent project is to write a client for a rest service, where the signature check needs to generate a date in RFC 1123 format in the HTTP header. This problem is better solved, simply skim the ph ...

  • 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.