search
Homephp教程php手册php中Y2K38的漏洞解决方法实例分析

这篇文章主要介绍了php中Y2K38的漏洞解决方法,以实例形式对php中Y2K38的漏洞的原理及相应的解决方法进行了较为深入的分析,需要的朋友可以参考下

本文实例分析了php中Y2K38漏洞的解决方法。分享给大家供大家参考。具体分析如下:

Y2K38,又称 Unix Millennium Bug, 此漏洞将会影响到所有 32 位系统下用 UNIX 时间戳整数来记录时间的 PHP,及其它编程语言。

一个整型的变量所能保存的最大时间为 2038 年 1 月 19 日 03:14:07。超过这个时间后,整型数值将会溢出。

从 1970 年 01 月 01 日开始,到世界标准时 2038 年 01 月 19 日星期二凌晨 03:14:07 超过 2^31 – 1。2^31 – 1 就是 0x7FFFFFFF,相信很多编程员都看过,在 32 位系统里,这表示最大的有符号整数。如果用它来表示秒数,大概相当于 68.1 年,从 1970 年到 2038 年刚好是这个数。

32位系统下显示2038年1月19日03:14:07以后的日期将会溢出。

那么64 位系统会受到影响吗?

理论上不会,强烈建议进行一下测试。64 位系统下可以保存的日期最远日期是现在宇宙年龄的 21 倍~ 292 亿年。

在32位机器上,,可以使用DateTime类来解决这个问题。(PHP5.2开始引入这个类,并在5.3版本中扩展了一些方法)

代码如下:

format('U'); // 2209032000 echo $dt->format('Y-m-d H:i:s'); // 2040-01-01 12:00:00 ?>

希望本文所述对大家PHP程序设计的学习有所帮助。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment