Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Counting hits to detailed pages

Quote Reply
Counting hits to detailed pages
hello, I want to count all the hits to my detailed pages. I have read the other post about couting to detailed pages but I don't know where and how to place all the code's. If anyone can help me with this I would apreciated it.

Thankx a lot already

Puffy Dog

Quote Reply
Re: Counting hits to detailed pages In reply to
You place the codes in the jump.cgi or if you use info.cgi (dynamic version of detailed pages), then you put the codes you've read in that file.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: Counting hits to detailed pages In reply to
but where do I place the code preciesly ?? I use info.cgi(detailed.cgi) Please help because I don't get it



http://candd.hypermart.net -- The best cocktailsite in the world !!
Quote Reply
Re: Counting hits to detailed pages In reply to
Go here: http://www.findinghim.com/...mods/jump_to_detail/

...instructions for redirecting through jump.cgi. but since you're using info.cgi you really should go ahead and hack info.cgi to do the counting itself to conserve bandwidth.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Counting hits to detailed pages In reply to
thankx for the site but as you say, know it will consume lot's of bandwidth.

I'm not that good at perl so I don't know preciesely which code to please where, it's something from jump.cgi, the counting part but copy and paste this part messes up the complete script so If somebody could explain me preciesly where to put what I would be really happy.

thankx already

Puffy Dog

http://candd.hypermart.net -- The best cocktailsite in the world !!
Quote Reply
Re: Counting hits to detailed pages In reply to
In info.cgi, replace sub main with the following:
Code:
sub main {
%in = &parse_form();
my (%rec) = &get_record ($in{'ID'});
if ($rec{$db_key} eq $in{'ID'}) {
if (open (HIT, "<$db_hits_path/$id")) {
my ($count, $old_time, @IP, $ip, $visited);
chomp ($count = <HIT>);
chomp ($old_time = <HIT>);
chomp (@IP = <HIT>);
(($time - $old_time) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
if (!$visited) {
push (@IP, $ENV{'REMOTE_ADDR'});
$count = $count + 1;
open (HIT, ">$db_hits_path/$id") or &error ("$cant_increment_counter");
if ($db_use_flock) { flock (HIT, 2) or &error ("$cant_flock"); }
local $" = "\n";
print HIT "$count\n$time\n@IP";
close HIT;
}
}
else {
open (HIT, ">$db_hits_path/$id") or &error ("$cant_increment_counter");
print HIT "1\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;
}
$title_unlinked = &build_unlinked_title ("$rec{'Category'}/$rec{'Title'}");
$title_linked = &build_linked_title ("$rec{'Category'}/$rec{'Title'}");
&html_print_headers;
print &site_html_detailed (%rec);
}
else {
&html_print_headers;
print &site_html_detailed_error ("Link not found or not specified.");
}
}
and let me know if that works.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Counting hits to detailed pages In reply to
thankx for the trying but it doesn't work, I'm sorry. When I access the detailed script for a ID the only thing that comes into my screen is 'Error' I will copy and paste the code below. Happy coding

Puffy Dog

##detailed.cgi##

#!/usr/local/bin/perl
# File:
# info.cgi
# Date:
# July 6, 2000
# Author:
# Philip Putnam, based on code by Alex Krohn
# Description:
# Builds a dynamic details page in place of wasting valuable disk space.
# On the other hand, now ther're potential bandwidth problems :-)
# Comments:
# This script was written as a replacement for detail.cgi by Jerry Su.
# It consists mostly of code snippets from jump.cgi, modify.cgi, and
# nph-build.cgi. The last few pieces I figured out on my own. Unlike
# Jerry's version, mine loads up an error page instead of redirecting to
# the root url or a blank page.
# Support:
# Since I'm not a perl expert, I can't claim this script is flawless.
# Please post your questions or comments regarding this script to the
# Gossamer-Threads Links 2.0 Customization forum.
# =====================================================================
#
# Setup Notes:
# Make sure the require statement below points to the config file.

# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \

require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}

# ========================================================

eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.

sub main {
# --------------------------------------------------------
%in = &parse_form();

my (%rec) = &get_record ($in{'ID'});

unless ($in{'ID'}) {
&html_print_headers;
print &site_html_detailed_error ("No link specified."); #future versions will load a form instead of an error
}
elsif ($rec{$db_key} eq $in{'ID'}) {
$title_unlinked = &build_unlinked_title ("$rec{'Category'}/$rec{'Title'}");
$title_linked = &build_linked_title ("$rec{'Category'}/$rec{'Title'}");
&html_print_headers;
print &site_html_detailed (%rec);
}
else {
&html_print_headers;
print &site_html_detailed_error ("Link $in{'ID'} not found.");
}
}

###
# Can't require nph-build -- have to copy this stuff :-)
###

sub build_linked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.

my $input = shift;
my (@dirs, $dir, $output, $path, $last);

@dirs = split (/\//, $input);
$last = &build_clean(pop @dirs);

$output = qq| <A HREF="$build_root_url/">Top</A> :|;
foreach $dir (@dirs) {
$path .= "/$dir";
$dir = &build_clean ($dir);
$output .= qq| <A HREF="$build_root_url$path/">$dir</A> :|;
}
$output .= " $last";

return $output;
}

sub build_unlinked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up by section.
# Useful for printing in the title.

my $input = shift;
my (@dirs, $dir, $output);

@dirs = split (/\//, $input);

$output = qq|$build_site_title > |;

foreach $dir (@dirs) {
$dir = &build_clean ($dir);
$output .= " $dir >";
}
chop ($output);
return $output;
}

###
# End of stuff we copied from nph-build.
###

sub error {
# ------------------------------------------
#
print "Content-type: text/html\n\n";
print "Error: $_[0]\n";
exit;
}




http://candd.hypermart.net -- The best cocktailsite in the world !!
Quote Reply
Re: Counting hits to detailed pages In reply to
My bad... Some of the codes in that subroutine are from an edited version of jump.cgi. But that's not really the problem. Replacing the error codes with the original reveals false errors (Can't open for output counter file ..etc.) and you know their wrong because jump.cgi works fine.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Counting hits to detailed pages In reply to
I tried it, I know get the following error:

Error: Can't open for output counter file. Reason: Is a directory

and I have exacly copied you code. I also looked at the jump.cgi and the link.cfg but I don't know what's wrong ?!

I chmod the 'hits' directory and the 'index.count' file both 777 but still not working, do you have an idea how to solve this ?? Thankx

Puffy Dog

http://candd.hypermart.net -- The best cocktailsite in the world !!
Quote Reply
Re: Counting hits to detailed pages In reply to
hits directory should be 777, but the index.count file should be 644.

Regards,

Eliot Lee
Quote Reply
Re: Counting hits to detailed pages In reply to
I thought I already said this (more or less): Jump.cgi has no problem opening and/or writing files, therefore, permissions and existance of certain files is not the problem. Therefore the only thing I can think of is that there must have been a coding error that occured when porting the codes over to info.cgi.

Happy Coding,

--Drew
http://www.FindingHim.com
Quote Reply
Re: Counting hits to detailed pages In reply to
I looked at that point also but there is no difference that can provide the error as above. Mayby someone else at who this worked ?? Thankx

http://candd.hypermart.net -- The best cocktailsite in the world !!