PHP, 22 bytes
`<?=PATH_SEPARATOR>":";`
prints 1
if the path separator is semicolon (colon or empty for all other OSs except for DOS and OS/2), else nothing.
also 22 bytes, but not that safe:
<?=strpos(__FILE__,92);
prints a positive integer if the file path contains a backslash; else nothing.
A safe alternative with 27 bytes: <?=DIRECTORY_SEPARATOR>"/";
prints 1
or nothing.
Strange: <?=__FILE__[1]==":";
(20 bytes) should be, not safe either, but ok. But although __FILE__
pretends to be a string (I tried var_dump
and gettype
), indexing it throws an error (at least in online testers).
I´ll try it on my server tomorrow. Will someone test it on Windows?
27 bytes: <?=stripos(PHP_OS,win)===0;
tests if predefined PHP_OS
constant starts with win
(case insensitive; Windows,WIN32,WINNT, but not CYGWIN or Darwin); prints 1
for Windows, else nothing.
17/18 bytes:
<?=strlen("
")-1;
prints 1
if it was stored with Windows linebreak (also on DOS, OS/2 and Atari TOS - although I doubt that anyone ever compiled PHP for TOS), else 0
.
You could also check the constant PHP_EOL
.
more options:
PHP_SHLIB_SUFFIX
is dll
on Windows, but not necessarily only there.
php_uname()
returns info on the operating system and more; starts with Windows
for Windows.
$_SERVER['HTTP_USER_AGENT']
will contain Windows
when called in a browser on Windows.
<?=defined(PHP_WINDOWS_VERSION_BUILD);
(38 bytes) works in PHP>=5.3
conclusion
The only failsafe way to tell if it´s really Windows, not anything looking like it, seems to be a check on the OS name. For PHP: php_os()
may be disabled for security reasons; but PHP_OS
will probably always contain the desired info.