This article mainly introduces the security method for PHP to output an English time and date. The time and date mentioned in this article is in RFC1123 format, and summarizes a gmdate function not affected by setlocale, for more information, see write a client for a rest service in the latest project. the signature verification must generate a Date in RFC 1123 format in the HTTP Header.
This problem is better solved. I simply read the PHP document and use the gmstrftime function to solve it.
The code is as follows:
String gmstrftime (string $ format [, int $ timestamp = time ()])
The call code is as follows:
The code is as follows:
Echo gmstrftime ("% a, % d % B % Y % T % Z", time ());
// Output: Tue, 01 Apr 2014 16:16:07 GMT
During debugging, it was found that on another computer, the output was not as expected, and then a Chinese character was generated:
The code is as follows:
2, 01 4 2014 16:20:02 GMT
Continue to read the document and find that the comments in the document indicate that the result of this function is affected by the setlocale result, which is influenced by the default language of the current system. Run the following command to view the language installed on the current system:
The code is as follows:
Locale-
Based on the analysis result, it is okay to set setlocale to English. the code is as follows:
The code is as follows:
Setlocale (LC_TIME, 'en _ us ');
Echo gmstrftime ("% a, % d % B % Y % T % Z", time ());
So far the article should have ended, but unfortunately on the Ubuntu machine for testing, because it is Live CD version, there is no en_US language, but there is a en_US.UTF-8. At this time the psychological drum, this approach seems not safe, I can not determine the client running the code, in the end there is en_US or there is a en_US.UTF-8. The comments section in the document can be replaced by gmdate. This function is not affected by the setlocale result:
The code is as follows:
Gmdate ('d, d m y h: I: s'). 'gmt ';
Case closed ~ Although the demand is small, it is not easy to write well, and more efforts will be made in the future.