Can PHP tell if the server os is 64-bit?

后端 未结 12 594
北荒
北荒 2020-12-09 08:52

I am dealing with Windows here.

I know you can use the $_SERVER[\'HTTP_USER_AGENT\'] variable to detect the OS of the browser viewing the page, but is t

12条回答
  •  青春惊慌失措
    2020-12-09 09:29

    Note: This solution is a bit less convenient and slower than @Salman A's answer. I would advice you to use his solution and check for PHP_INT_SIZE == 8 to see if you're on a 64bit os.

    If you just want to answer the 32bit/64bit question, a sneaky little function like this would do the trick (taking advantage of the intval function's way of handling ints based on 32/64 bit.)

    
    

    You can see the code in action here: http://ideone.com/JWKIf

    Note: If the OS is 64bit but running a 32 bit version of php, the function will return false (32 bit)...

提交回复
热议问题