Detecting Windows or *ix?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Schroeder, AJ

    Detecting Windows or *ix?

    Hello group,

    I have a few PHP scripts that poll switches and routers via SNMP. Depending
    on the user, the scripts can be run from either Windows XP or *ix (FreeBSD,
    Redhat, etc)

    I am beginning to implement syslog() and openlog() in my scripts and there
    are some suddle differences in how PHP logs to event viewer in Windows and
    syslog in everything else. About the most reliable method I have found in
    detecting Windows is a simple check to see if $_SERVER['OS'] is defined,
    which returns "Windows_NT ". On Redhat it doesn't come back as defined at
    all, so that makes the code easy.

    I'm sure I am not the first one to attempt this, can anyone else share their
    experiences with this and maybe offer a better way other than checking for a
    predefined constant?

    Thanks,

    AJ Schroeder


  • ZeldorBlat

    #2
    Re: Detecting Windows or *ix?

    On Jul 3, 10:23 am, "Schroeder, AJ" <a...@qg.comwro te:
    Hello group,
    >
    I have a few PHP scripts that poll switches and routers via SNMP. Depending
    on the user, the scripts can be run from either Windows XP or *ix (FreeBSD,
    Redhat, etc)
    >
    I am beginning to implement syslog() and openlog() in my scripts and there
    are some suddle differences in how PHP logs to event viewer in Windows and
    syslog in everything else. About the most reliable method I have found in
    detecting Windows is a simple check to see if $_SERVER['OS'] is defined,
    which returns "Windows_NT ". On Redhat it doesn't come back as defined at
    all, so that makes the code easy.
    >
    I'm sure I am not the first one to attempt this, can anyone else share their
    experiences with this and maybe offer a better way other than checking for a
    predefined constant?
    >
    Thanks,
    >
    AJ Schroeder
    There are lots of ways. You could even look at the constant
    DIRECTORY_SEPAR ATOR to see if it's / or \ -- I have yet to find a *nix
    system that uses \ and a Windows system that uses /.

    Comment

    • gosha bine

      #3
      Re: Detecting Windows or *ix?

      On 03.07.2007 16:23 Schroeder, AJ wrote:
      Hello group,
      >
      I have a few PHP scripts that poll switches and routers via SNMP. Depending
      on the user, the scripts can be run from either Windows XP or *ix (FreeBSD,
      Redhat, etc)
      >
      I am beginning to implement syslog() and openlog() in my scripts and there
      are some suddle differences in how PHP logs to event viewer in Windows and
      syslog in everything else. About the most reliable method I have found in
      detecting Windows is a simple check to see if $_SERVER['OS'] is defined,
      which returns "Windows_NT ". On Redhat it doesn't come back as defined at
      all, so that makes the code easy.
      >
      I'm sure I am not the first one to attempt this, can anyone else share their
      experiences with this and maybe offer a better way other than checking for a
      predefined constant?
      >
      Thanks,
      >
      AJ Schroeder
      >
      >
      hi there

      look for php_uname()


      --
      gosha bine

      extended php parser ~ http://code.google.com/p/pihipi
      blok ~ http://www.tagarga.com/blok

      Comment

      • =?ISO-8859-15?Q?Oliver_Gr=E4tz?=

        #4
        Re: Detecting Windows or *ix?

        Schroeder, AJ schrieb:
        Hello group,

        I have a few PHP scripts that poll switches and routers via SNMP. Depending
        on the user, the scripts can be run from either Windows XP or *ix (FreeBSD,
        Redhat, etc)

        I am beginning to implement syslog() and openlog() in my scripts and there
        are some suddle differences in how PHP logs to event viewer in Windows and
        syslog in everything else. About the most reliable method I have found in
        detecting Windows is a simple check to see if $_SERVER['OS'] is defined,
        which returns "Windows_NT ". On Redhat it doesn't come back as defined at
        all, so that makes the code easy.

        I'm sure I am not the first one to attempt this, can anyone else share their
        experiences with this and maybe offer a better way other than checking for a
        predefined constant?
        Why? What's the problema with the constant PHP_OS ?

        OLLi

        --
        Die Tür zur Vergangenheit kann man nicht öffnen, ohne dass sie knarrt.
        [Der Adler 103]

        Comment

        • Schroeder, AJ

          #5
          Re: Detecting Windows or *ix?

          Oliver Grätz wrote:
          Schroeder, AJ schrieb:
          >Hello group,
          >>
          >I have a few PHP scripts that poll switches and routers via SNMP.
          >Depending on the user, the scripts can be run from either Windows XP
          >or *ix (FreeBSD, Redhat, etc)
          >>
          >I am beginning to implement syslog() and openlog() in my scripts and
          >there are some suddle differences in how PHP logs to event viewer in
          >Windows and syslog in everything else. About the most reliable
          >method I have found in detecting Windows is a simple check to see if
          >$_SERVER['OS'] is defined, which returns "Windows_NT ". On Redhat it
          >doesn't come back as defined at all, so that makes the code easy.
          >>
          >I'm sure I am not the first one to attempt this, can anyone else
          >share their experiences with this and maybe offer a better way other
          >than checking for a predefined constant?
          >
          Why? What's the problema with the constant PHP_OS ?
          >
          OLLi
          No problem... I guess I didn't know about it since I always ran the scripts
          from Redhat.

          I am using a the constants PHP_OS and DIRECTORY_SEPAR ATOR to check and see
          what os the script is running from.

          I also didn't know about php_uname(), so I am using that for something in my
          scripts, too.

          Thank you to all who responded, the suggestions really helped!

          AJ Schroeder


          Comment

          Working...