-
☆ A M B ☆
- 2,475 Posts
Is there a MODx method for getting request data? I want to log IPs and User Agent strings... I can read this out of the various server variables, but I was wondering if MODx already had built out some of this somewhere...
Thanks!
-
☆ A M B ☆
- 24,524 Posts
No need for any wrappers for that; a snippet or plugin is the way to get the SERVER variables.
I was just playing around with a plugin to log page-not-found requests. I'm writing them to a chunk, but you could just as well write them to a file. I don't know if the double sanitizing is really necessary or not. The data is stored as a comma-separated list, so you'd need a snippet to display it properly (the function that writes the data adds a "\n" at the end).
<?php
function getHost($ip){
$ptr= implode(".",array_reverse(explode(".",$ip))).".in-addr.arpa";
$host = dns_get_record($ptr,DNS_PTR);
if ($host == null) return $ip;
else return $host[0]['target'];
}
$data['page'] = htmlentities(strip_tags($_SERVER['REQUEST_URI']));
$data['ip'] = htmlentities(strip_tags($_SERVER['REMOTE_ADDR']));
$data['userAgent'] = htmlentities(strip_tags($_SERVER['HTTP_USER_AGENT']));
$data['host'] = getHost($ip);
$msg = implode(',', $data);
/* log data */
my_debug($msg);