Search code examples
phpwindowsevent-log

Read Windows Event Log with PHP


Is there any way to read Windows Event Log with PHP?

To be specific, I want to read windows users' logon & logoff activities with corresponding user names. I am using PHP with wamp server.


Solution

  • I couldn't find a way to read Window's Event Log directly. But in my case I wanted have Logon & Logoff info. So I manage that in another way.

    wrote two .bat files as follows.

    LogOn.bat; Which includes the following code.

    echo Login %Date% %TIME% %USERNAME% >> {Directory path to log folder}\%Date%.txt
    

    LogOff.bat; which includes the following code.

    echo LogOff %Date% %TIME% %USERNAME% >> {Directory path to log folder}\%Date%.txt
    

    Then added these files to logon & logoff scripts. Bellow are the steps.

    • Open "Edit Group Policy" in windows.
    • Double click on "User Configuration" from the right pane.
    • Double click on "Windows Settings" from the right pane.
    • Double click on "Scripts (Logon/Logoff)"
    • Then double click on "Logon" and add previously prepared LogOn.bat file to the container.
    • Do same for the "Logoff" and add LogOff.bat.

    Note; This will log, logon & logoff information into a file name with Day. You can change the file name as your preference.

    At the end I could read the logged text files via PHP. Hope this helps to someone.