Adding host logging to the Guestbook Application
One of the people who downloaded the Guestbook application wrote me to show the modifications he made. He wanted to also track the IP or Hostname of the people posting so he made some slight modifications to the database and the parts of the script that insert the data into the database. Here are those modifications and his email:
I am using your guestbook php script at http://www.queima.com, i did some changes on the visual and a small change to the script, so that it records the hostname of the person leaving the message. CREATE TABLE guests ( guest_id int(4) unsigned zerofill DEFAULT '0000' NOT NULL auto_increment, guest_name varchar(50), guest_email varchar(50), guest_time timestamp(14), guest_message text, guest_host varchar(100) NOT NULL, PRIMARY KEY (guest_id) ); and to the part that adds the message to the database: //////////////////////////////// // This is the meat of the query that updates the guests table //////////////////////////////// $ip = getenv("REMOTE_ADDR"); $ip1 = gethostbyaddr($ip); $query = "INSERT INTO guests "; $query .= "(guest_id, guest_name, "; $query .= "guest_email, guest_time, guest_message, guest_host) "; $query .= "values(0000,'$name','$email',NULL,'$message','$ip1')"; If it cannot get the host name from the IP it will leav the ip only. To make things faster (the time it takes to do the reverse dns lookup) $ip = getenv("REMOTE_ADDR"); $query = "INSERT INTO guests "; $query .= "(guest_id, guest_name, "; $query .= "guest_email, guest_time, guest_message, guest_host) "; $query .= "values(0000,'$name','$email',NULL,'$message','$ip')"; Your small script is really good and simple, and it does the work. Gustavo Felisberto
Thanks Gustavo!