Search code examples
phpwindowsscreenshotdesktop

Screenshot of server's desktop using PHP


Is there any way of taking screenshots of my server's desktop using PHP, so that they can be presented to my website's remote administration page?

I am running a Windows Server 2008, but would be interested in a *nix alternative aswell for future purposes.


Solution

  • Will only work on Windows based servers, but how about:

    <?php
    // capture the screen
    $img = imagegrabscreen();
    imagepng($img, 'screenshot.png');
    ?>
    

    Or:

    <?php
    // Capture the browser window
    $Browser = new COM('InternetExplorer.Application');
    $Browserhandle = $Browser->HWND;
    $Browser->Visible = true;
    $Browser->Fullscreen = true;
    $Browser->Navigate('http://www.stackoverflow.com');
    
    while($Browser->Busy){
      com_message_pump(4000);
    }
    
    $img = imagegrabwindow($Browserhandle, 0);
    $Browser->Quit();
    imagepng($img, 'screenshot.png');
    ?>
    

    Searching is useful for a fast answer ;)

    Website screenshots using PHP