I.T. Security and Linux Administration

Sep 30 2011   9:22PM GMT

[PHP] Lighttpd Access Log Viewer

Eric Hansen Eric Hansen Profile: Eric Hansen

In an earlier post I made, Lighttpd Access Log Parsing, I wrote a quick Bash line to parse Lighttpd’s access log file that you can easily port over to any other log file.  This time, I’ve done the same thing, but with PHP (using HTML for output, but you can change that if you like).  Click continue to see the awesome powers PHP can have with some regex magic, and basic HTML!

Going to start this off with the script, and then explain any of the finer details that I feel should be addressed. As the script doesn’t correctly show up in this blog, I’ve uploaded it to pastebin (due to the HTML, it conflicts with the PHP coding as well): http://pastebin.com/82fkhrjX

Since this is a basic version of a log analyzer, it doesn’t have all the bells and whistles, but that’s why I started work on the “parser()” function, which already handles IP addresses.

There’s not a whole lot that needs to be actually addressed, as it uses all regular PHP functions without the need for external libraries (minus libpcre for regex). The regex does the same thing as the Bash line does in the previous article, but makes it easier to manage as each line will be the first array. Originally I was going to write this as a command line script, but I decided to make it HTML instead, which is why some of the variables aren’t actually used, even though I set them (which also just makes it easier in the end if you do want a CLI version).

All you need to do is save it to your computer/server, give it executable rights (and change the shabang to the correct php-cli path if needed), and run it…as well as editing the variables $file and $data_path.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: