I wanna try to collect statistics for my wordpress website with my own plugin. the information I need is stored in $_SERVER variable. by surfing the Internet, I've two useful hooks to insert my code:
- parse_request 2. init
Everything works fine with localhost. no data is missed, no matter it's by mobile phone or desktop, from page links or offline documents, inside apps or browser.
while it's running online, something is different. After several days collecting, i've found the collected info is not complete; sometimes i visited the website directly with mobile phone through browser or inside an app, the info will not be recorded. but I checked the access.log, it's normal. And when running on localhost, data is saved soundly. I cannot figure out why when put online, it will omit some data
function get_statistics(){
global $wpdb;
$table_name = 'table_name';
$split_str = 'separation_str';
$logdata=$_SERVER['REQUEST_TIME'].$split_str.$_SERVER['HTTP_REFERER'].$split_str.$_SERVER['HTTP_USER_AGENT'].$split_str.$_SERVER['REMOTE_ADDR'].$split_str.$_SERVER['REQUEST_URI'].$split_str.$_SERVER['HTTP_COOKIE'];
$logdata =substr($logdata,0,1500);
$wpdb->query( $wpdb->prepare( 'insert into '.$table_name.'(logdata) values(%s)', $logdata) );}
add_action('init','get_statistics',1);