Posted by aparks (aparks), 9 February 2004I have some firewall log data file of the form:
Source IP, Destination IP, Protocol, Destination Port
and I'd like to present this on a web page so that it ends up like:
Source IP, Destination IP, Protocol, Destination Port, Number of packets
But I'm not sure the best way to go about this. I'm thinking that it can be done by reading each field in with a multi-dimensional array with code something like:
and then run through this in a nested loop to print it all out in a table, but is this an efficient way to go about it? Is there a better way? Multi-dimensional arrays make my head hurt!
Adrian (looking for the aspirin)
Posted by admin (Graham Ellis), 9 February 2004I would be inclined just to use the whole of each logfile line as one massive key and write
and the output using
Oh - you'll need to trim the new line off the log file line - either when you read it in or before you output it.
Where a multidimensional array would start to be useful is if you wanted to start providing totals of rows / columns etc.
Posted by aparks (aparks), 9 February 2004That looks much better - thanks!
Posted by aparks (aparks), 9 February 2004er...slight problem still! The code produces the output I was looking for, but also a lot of warnings of the following type:
Notice: Undefined index 172.16.3.3,192,168.1.1,TCP,21 in script.php on line xxx
referring to the line
This is presumably because this is the first time $packet[$logfile_line] is referred to, as it hasn't been previously defined. But how do I suppress these messages? I assume I could turn them off globally somewhere in php.ini on the server, but is it possible from within the code?
Posted by admin (Graham Ellis), 9 February 2004Two possible solutions ...
You could check whether the array member exists (see isset) ... inialise it to 1 if it is new and increment it by one if it already exists
You turn off notices by specifiying
before you start building us the array
Posted by aparks (aparks), 9 February 2004That's done it! Many thanks for all your help, Graham!
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho