![]() |
Help search through file....
Hey guys, I need to read through my apache error_log file and filter out only what I'm looking for. (specific IP addresses)
Below is the normal format in the file: 192.168.2.1 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.3 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.3 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.5 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.5 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.1 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 Here's my code but it doesn't seem to work right? What I'm trying to do is, as I read through the file, output anything that matches in the array.... Code:
<?php192.168.2.1 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.3 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.3 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 192.168.2.1 - - [20/Mar/2009:21:03:38 -0400] "GET /index.php HTTP/1.1" 200 58 |
Try this way:
PHP Code:
|
If you want simple, perhaps something along the lines of the following would suffice.
PHP Code:
PHP Code:
|
Thanks to both you guys!
I am going to attempt Sal's OOP way since I'm trying to learn OOP, might as well start with this... I'll give it a shot and see how it turns out! |
It's amazing how much shorter the procedural way is.
But I know what the power of OOP can bring to me if I keep at it..... |
Hey Salathe,
I am getting this error when I run it. Quote:
|
The error says that there is no such file or directory called "error.log". Is the error.log file in the same directory as the script?
|
Quote:
Ohhh I am such a fool!! The name of my file is called: error_log And I called the file: error.log hahaha.. That's what happens when you roll out of bed and the coffee doesn't kick in yet and you try to program... It works now perfectly!!! If you don't mind, I am going to try attempt to comment on your code and if you can be so kind to point out where I may be wrong? I want to make sure I understand this OOP stuff.... |
Ok Salathe:
Here is my attempt at commenting your code. Please let me know where I am wrong. Also, the method accept(), if you can explain that further because I don't see that called anywhere?? Thanks!! Code:
<?php |
|
Quote:
Wow I cannot thank you enough. The Thank You button only let's me click on it once... :-P I've read about 3-4 books on OOP the last 2 months. My favorite is this one: The Object-Oriented Thought Process by Matt Wiesfeld. Maybe you've read it or heard of it, but I like that it's not PHP related but just the overall thought process of OO design. Anyways, this OO stuff is taking a long time for it to sink in for me. Especially things like method overloading, and the many types of design patterns. Thanks again and I am still going to look at your code so I fully understand it. In all the books I've read, I don't recall reading up on Method chaining so I'll have to do some digging on that, sounds pretty important!!! (unless there's another term out there for method chaining?) |
| All times are GMT. The time now is 06:50 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0