Parsing Apache logs


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //Logs: Apache web server
  2. //Successful hits to HTML files only. Useful for counting the number of page views.
  3. '^((?#client IP or domain name)S+)s+((?#basic authentication)S+s+S+)s+[((?#date and time)[^]]+)]s+"(?:GET|POST|HEAD) ((?#file)/[^ ?"]+?.html?)??((?#parameters)[^ ?"]+)? HTTP/[0-9.]+"s+(?#status code)200s+((?#bytes transferred)[-0-9]+)s+"((?#referrer)[^"]*)"s+"((?#user agent)[^"]*)"$'
  4.  
  5. //Logs: Apache web server
  6. //404 errors only
  7. '^((?#client IP or domain name)S+)s+((?#basic authentication)S+s+S+)s+[((?#date and time)[^]]+)]s+"(?:GET|POST|HEAD) ((?#file)[^ ?"]+)??((?#parameters)[^ ?"]+)? HTTP/[0-9.]+"s+(?#status code)404s+((?#bytes transferred)[-0-9]+)s+"((?#referrer)[^"]*)"s+"((?#user agent)[^"]*)"$'

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.