Leetfail
Leetfail

Reputation: 133

Any way to print contents of a screen to a web page?

I'm running a minecraft server on a screen (screen -X mc java -jar minecraft_server.jar). Is there any way to print the contents of this onto a web page? I was thinking it would be something along the lines of

<?php
$console = exec(console.sh)
echo $console;
header("refresh: 5";);
?>

however this does not print anything. I think it has something to do with the screens being per-user, is there any way to let php run this? Or is there anyway to output the screen to a file and still be able to attach to the screen?

Thanks a ton!

Edit: Answer below works well, however I would suggest http://phpshell.sourceforge.net. You can log into the terminal and display the console along with being able to chat. However this is interactive, and would work only for admins.

Upvotes: 2

Views: 113

Answers (1)

Jacob R
Jacob R

Reputation: 430

Either of these should work.

<?php
$logs = "PATH_TO_SERVER_LOGS/server.log";
$fh = fopen($logs, 'r');
$theData = fread($fh, filesize($logs));
fclose($fh);
echo $theData;
header("refresh: 5");
?>

<?php
//Replace ./server.log with the path to your server logs and make sure apache has the proper //permissions to read the file.
$file = file_get_contents('./server.log', true);
echo $file;
header("refresh: 5");
?>

Upvotes: 3

Related Questions