CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
cgi script log file

 



steelrat
Deleted

May 4, 2000, 1:05 AM

Post #1 of 3 (702 views)
cgi script log file Can't Post

Please can you help me, I am trying to write a CGI script that behaves as follows;
every time a browser requests an image from a particular page, the script captures
the IP address of the browser and appends it to a file.
This 'log-file' needs to be in the form of an HTML document.

Thanking you in advance,

steelrat


computersmarts
Deleted

May 4, 2000, 5:53 AM

Post #2 of 3 (702 views)
Re: cgi script log file [In reply to] Can't Post

This might do it for you... it's nothing fancy but it will give you a good base. Some ideas could be also adding the date to it so you know when, maybe also the time. Well I hope this does something for you. Just let me know.

#!/usr/bin/perl5.004


# NOTE: make sure you create a file called
# log.html and place it in the appropriate
# place on your server.
# ALSO: you can access this script
# with server side include by entering
# <!--#exec cgi="/cgi-bin/counter.cgi"-->
# into whatever page you want to log from.
# Hope this gives you something to at least start
# with, enjoy!
# M.M. computersmarts.net

print "Content-type: text/html\n\n";


#####################################################
# This is the URL of where you image is located #
#####################################################
$imageurl = "http://www.whoknows.com/images/log.gif";


#####################################################
# This is the PATH to where it will store the IP's #
#####################################################

$logfile = "/home/computersmarts/www"; # NO FORWARD /

#####################################################
# And here is the script in action #
#####################################################


open(DOC,">>$logfile/log.html") | | die $!;
print DOC "<p>$ENV{'REMOTE_ADDR'}</p>";
close(DOC);
# printing to the HTML file

print "<p><img border=\"0\" src=\"$imageurl\"></p>";
# displaying image for all the world to see. [don't remove \'s]

exit;

=============================
Webmaster
ComputerSmarts.net
The Search Engine for Programmers.


[This message has been edited by computersmarts (edited 05-04-2000).]


steelrat
Deleted

May 6, 2000, 4:43 AM

Post #3 of 3 (702 views)
Re: cgi script log file [In reply to] Can't Post

Cheers ComputerSmarts, that looks like a good start indeed; I've tried to incorporate my own server settings and path details, but I'm afraid my script 'exploded' - can you spot any glaring errors! P.S.-my username is hilesp on the college server.

#!/usr/bin/perl


# NOTE: make sure you create a file called
# log.html and place it in the appropriate
# place on your server.
# ALSO: you can access this script
# with server side include by entering
# <!--#exec cgi="/cgi-bin/counter.cgi"-->
# into whatever page you want to log from.
# Hope this gives you something to at least to start
# with, enjoy!
# M.M. computersmarts.net

print "Content-type: text/html\n\n";


#####################################################
# This is the URL of where you image is located #
#####################################################
$imageurl = "http://www.sbu.ac.uk/~hilesp/images/log.gif";


#####################################################
# This is the PATH to where it will store the IP's #
#####################################################

$logfile = "/~hilesp/sbu.ac.uk/www"; # NO FORWARD /

#####################################################
# And here is the script in action #
#####################################################


open(DOC,">>$logfile/log.html") | | die $!;
print DOC "<p>$ENV{'REMOTE_ADDR'}</p>";
close(DOC);
# printing to the HTML file

print "<p><img border=\"0\" src=\"$imageurl\"></p>";
# displaying image for all the world to see. [don't remove \'s]

exit;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives