Shammer's Philosophy

My private adversaria

Using PHP on Debian apache2

I am using Debian and Apache2 in my test environment, just returning some text via http. In my purpose, I hope that apache2 returns timestamp and hostname and use python to do it. Here is a python script doing it.

#!/usr/bin/env python
from socket import gethostname
from time import gmtime, strftime

print "Content-Type:text/plain"
print "Set-Cookie: Auth-Key=9dIqSv5VzBG+tQLSyV56wlZl5E887Q5O4jzK00GBHS8=; path=/; Max-Age=604800;; Path=/; Version=1\r\n"

s = strftime("%b %d %Y %H:%M:%S", gmtime()) + " " + gethostname()
print s

But, I want to replace this script more simple and select php. Following php script returns the message I hope.

<?php
echo 'Received from '.gethostbyaddr(gethostbyname(gethostname())).' at '.date('Y-m-d H:m:s')."\n";
?>

PHP is more simple to enable on apache2, just apt-get install php5 enables php on apache2.
I use the format 'Y-m-d H:m:s', Y means year as integer, m means month as integer, d means day as integer.
And H means hour with 24 hours, we can use h instead of H if we want to display hour as 12 hours.
The m in H:m:s means a minute, s means a second.