setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stm="CREATE TABLE IF NOT EXISTS log ( id integer primary key autoincrement, sessionid TEXT, msg TEXT, date TEXT );"; $db -> exec($stm); $i=""; if (getenv("SEARCHREQUEST") !== false) { $msg=htmlentities(getenv("SEARCHREQUEST")); $sessionid = $_SERVER["SESSION_ID"]; date_default_timezone_set('Europe/Paris'); $d = new DateTime(); $date = $d->format('r'); if ((isset($msg)) && (!empty($msg))) { $i="i"; try { $stm = $db->prepare("INSERT INTO log (sessionid,msg,date) VALUES (:sessionid,:msg,:date)"); $stm -> execute([ 'sessionid' => $sessionid, 'msg' => $msg, 'date' => $date ]); } catch(Exception $e) { $db->rollback(); throw $e; } } } // print out guestbook comments $stm = $db->query("SELECT `sessionid`, `msg`,`date` FROM `log` ORDER BY id DESC"); while ($row = $stm->fetch()) { $sessionid=$row['sessionid']; $date=$row['date']; $msg=$row['msg']; if (!empty($msg)) { // prepend "i" to each line if gophermap echo $i."+".str_repeat("-", 65)."+\n"; echo $i."[".$sessionid."] ".date("H:i, l jS F Y", strtotime($date))."\n"; echo $i."+".str_repeat("-", 65)."+\n"; // get a clean string for passing to the shell $msg = escapeshellarg(html_entity_decode($msg)); // format string newline on words $msg = shell_exec("echo $msg | par w67"); // split lines to array $ma = explode(PHP_EOL, $msg); foreach ($ma as $msgline) { $msgline = stripslashes(trim($msgline,'\'"')); echo $i.$msgline."\n"; } } } ?>