Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Writing CGI Applications with Perl    (ISBN: 0201710145)


 

 List Price: $44.99
 Our Price: $31.49
 Used Price: $13.00

 Release Date: 15 February, 2001
 Manufacturer: Addison-Wesley Pub Co (Paperback)
 Sales Rank: 99,576

 Author: Kevin Meltzer, Brent Michalski









More Info

 Host Log 2002-05-13 18:21:50
  perl 
Category: source:perl:cgi
Description: This is an example of how to descretely log the ip, date, and time users accessed your website.
Platform: unix
Author: Snap
Viewed: 1740
Rating: 5/5 (1 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
hostlog.cgi
#!/usr/bin/perl

##########################################
#                                        #
#   Written by Snap                      #
#           (iam@someoneshouse.com)      #
#                                        #
#   For Metalshell                       #
#       http://www.metalshell.com        #
#                                        #
#  This is an example of how to          #
#  descretely log user information as    #
#  they come in on your web site.  All   #
#  information is logged for private     #
#  viewing, with minimal output to the   #
#  user.  This can be easily             #
#  customized/changed.                   #
##########################################

#Change the following to the path/name you want the counter to be
$cFile="cgi-bin/counterfile";

#Change the following to the path/name you want your users info stored
$logFile="cgi-bin/logfile";

#Just the basic counter, can be used in conjunction with
#the "counter" example
open(OFILE,"$cFile");
$ctr=<OFILE>;
$ctr++;
close(OFILE);

open(WFILE,">$cFile") || `cat /dev/null > $cFile;chmod 666 $cFile`;
print WFILE $ctr;
close(WFILE);

#Change this to whatever date variables you want to pass
#but remember to change the search strings accordingly
#currently to set to format "DayofWeek Month Day Year"
$date=`date +%A%t%B%%%d%t%Y`;
$date=~s/       /, /gi;
$date=~s/%/ /gi;

#Again, this is customizeable
#current settings: 12hour format "hour:minute am/pm"
$time=`date +%l%%%M%t%p`;
$time=~s/%/:/gi;
$time=~s/       / /gi;

#Get rid of annoying returns(asthetics)
chomp $date;
chomp $time;

#Record to your log File
open(LOGGER,">>$logFile") || `cat /dev/null > $logFile;chmod 666 $logFile`;;
print LOGGER "\nNumber $ctr showed up on $date at $time from $ENV{REMOTE_ADDR}\n";
close(LOGGER);

#Checks to see if host can be resovled
$res=$ENV{REMOTE_HOST};
if($res eq ""){
$response="";
}elsif($res ne ""){
$response="Resolved: $res";
}

#This is the only output from the script, just to let them know you're watching
print "<center>You have been logged from: $ENV{REMOTE_ADDR}<br>$res</center>";
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?