HomeForumsWhat's newResources 
 
 
A bit of perl code
RitualOfTheTrout - Jan 14, 2006
   RitualOfTheTrout Jan 14, 2006 
I wrote a small program for my website, it simply grabbed the users browser, reffering url, IP, and time of visit and stored it into a text file. I used it mainly to see what the bulk of my visitors were using and how they found the site.

Now it worked fine up until about the end of december when all of the sudden it stopped showing new visitor info. I emailed the server folks and they said they do not help troubleshoot users scripts. So Im wondering if anyone here knows if thee was an update to perl or something that took place recently that may cause my script to quit working. Here is the script maybe somone could see if there is an error or something.

Below the script is the line of code in my HTML that sends the data to the script. The exec command was disabled so this was the only way I could find to make it run.

#!/usr/bin/perl

use CGI qw/:all/;

#

#

my @values = split(/&&&&&/,$ENV{QUERY_STRING});

$timestamp = localtime();

#

open(OUTFV, ">>userlog1.txt") || die("Cannot Open File");

flock (OUTFV, 2);

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

#

#

print OUTFV "Date: $timestamp\n";

print OUTFV "IP Address: $values[1]\n";

print OUTFV "Screen Name: $values[2]\n";

print OUTFV "HTTP Referer: $values[0]\n";

print OUTFV "Browser: $ENV{HTTP_USER_AGENT}\n\n";

print OUTFV " \n\n";

close(OUTFV);

/cgi-bin/log.cgi?<!--#echo var=

Any inout of any type would be greatly appreciated.

   vbt Jan 14, 2006 
Do you have acces to the server log, the error line is written inside.

You could catch an error on flock

I you don't have an access to the logs, you can do simple print before each command.

Also I guess you use shtml directives, if the http server has changed you can try

or

but exec cgi can be locked on apache

   slinga Jan 14, 2006 
Check the permissions of the file your writing to.

   dibz Jan 16, 2006 
Why not parse the apache access log? It should have all that information.

   RitualOfTheTrout Jan 18, 2006 

  
Originally posted by dibz@Tue, 2006-01-17 @ 04:05 AM

Why not parse the apache access log? It should have all that information.

[post=143523]Quoted post[/post]


Hmm I will look into that, Im fairly new to any sort of web programing outside of HTML and basic java script and CSS so I was not even aware of this option.

My site is on angelfire right now, so I might not have the rights to do that, I will hafta see.

Iv thought of setting up my own apache or IIS server on a win 2003 machine but im not sure I know enough about security issues to keep it from getting hacked.

   dibz Jan 18, 2006 
Not sure if a place like angelfire would allow that, but most places if you can view your logs you can check your own domlogs. It has pretty much exactly the same info and is better at tracking.

   vbt Jan 18, 2006 
this :

<img src="/cgi-bin/log.cgi

should not be allowed to run a cgi script.

Why don't you try

   dibz Jan 19, 2006 
Incorrect vbt, the command you gave is to use the cgi as a server side include which is partially correct. There is no reason it needs to be ran as a server side include. If he sets the cgi to return image output and also do the logging he wants, using it in an image tag would be fine as its just like any other request, it won't technically log the exact same request, but the difference would be nill. He may need to create an .htaccess rule for it to rewrite a request for what looks like a real image like and have it redirect to the script, and then the script does its thing and say outputs a "you have been logged" image or something retarded, or it could be a logo or a 1 pixel transparent gif.

Edit: the reason it would need to be something like is simply because some browsers refuse to load some things as images if they have invalid extensions.

   RitualOfTheTrout Jan 24, 2006 
Well after I emailed angelfire several times all of the sudden the exact code I posted above is now working agian.. hmmm seems odd

One other question, when you submit a form it automatically redirects you to like a confirmation or thankyou page. I cant seem to find the code or a guide on how to write the cgi code to do that.

Anyone know of a good place to find that or just know off hand a way to do it?

   dibz Jan 25, 2006 
Just have your script echo in the header:

Location:http://mydomain.com/thankyou.etc...

   RitualOfTheTrout Jan 25, 2006 
Well I finally got it to work, I had

print "Content-type: text/html\n"; near the start of the file for some reason so it just kept printing the url in the browser screen, took me like 2 hours to figure it out.

Now, is there anyway to append text files at the begining rather than at the end? I read about Tie::File, but its not installed and I have no way of installing it. Id also like to avoid reading the entire file into memory as over time it may become large.

Im just trying to make a real basic guestbook and I would like the the newest post to be the first thing in the file.

Thanks for all your help everyone.

   dibz Jan 26, 2006 
How are you reading the file? Have it read it in by chunks.