|
|
Subject:
Logging PHP Script
Category: Computers > Programming Asked by: theboistard-ga List Price: $45.00 |
Posted:
29 Jul 2004 05:52 PDT
Expires: 28 Aug 2004 05:52 PDT Question ID: 380702 |
I need a simple script that myself, being PHP clueless unable to setup properly. I need to be as simple as possible (look at my other question), without any extra HTML, any extra functions, without additional HTML headers, messages or interface and so on. The simpler and shorter it is, the better. The script should do the following: 1. Log the Visitor IP to a txt file (one IP per line) appending it to the END of the file. 2. If the text file is larger than X (lets say 1000) IP entries, then it should update the whole list, removing the first entry and adding the current/freshest one to the end -- ultimately updating the list and keeping it at a constant X (1000) number of entries. 3. The simpler & shorter, the better 4. Please use unique variables, I would like to use this as an include in another script and do not want the variables to interfere 5. If possible, do not use custom functions 6. If possible, both UNIX/win compatible 7. If possible, please test it on your own PHP server Thank you |
|
Subject:
Re: Logging PHP Script
Answered By: palitoy-ga on 29 Jul 2004 07:13 PDT Rated: |
Hello theboistard I have written the following script for you, if you have any questions on it please ask for clarification and I will do my best to help. You will need to add this script and a file called ip.txt to your server. You should CHMOD ip.txt to 777. <? # name of the file that stores the ip addresses $iplog_log_file = "ip.txt"; # read the ip address file into an array $iplog_lines = file( $iplog_log_file ); # get the ip address of the current user $iplog_ip = getenv('REMOTE_ADDR'); # add the ip address to the array $iplog_lines[] = $iplog_ip; # count the number of lines in the array, if there are # more than 1000 then skip the first if ( count($iplog_lines) >= 1000 ) { $iplog_start = 1; } else { $iplog_start = 0; }; # prepare the data for output for ( $iplog_i=$iplog_start; $iplog_i<1000; $iplog_i++ ) { if ( chop($iplog_lines[$iplog_i]) == "" ) { } else { $iplog_Data = $iplog_Data . chop($iplog_lines[$iplog_i]) . "\n"; }; } // save the file if($iplog_file=fopen($iplog_log_file, "w")) { // open file for writing fwrite($iplog_file, $iplog_Data); // write to file }; fclose($iplog_file); ?> | |
| |
| |
| |
|
theboistard-ga
rated this answer:
and gave an additional tip of:
$10.00
Its you, my PHP hero again! Once again palitoy has done a great job in providing me with a quick solution that I needed. I really appreciate the help, since I am PHP clueless (ex: it took me half an hour to set up the script because I changed a few variable names, and did not understand the write part) Thank you so very much palitoy |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |