Gossamer Forum
Home : Products : Links 2.0 : Customization :

How can I make the Hit count go up when the user clicks the link to the DETAILED view

Quote Reply
How can I make the Hit count go up when the user clicks the link to the DETAILED view
My Links (not yet published) does not have URL links but rather only links to a "Detailed" view of that links information. When you do this the HIT count does not go up because the link looks like this:

<a href="$build_detail_url">/$rec{$db_key}$build_extension

Rather than this:

<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">

Where the later of the two causes the link to count up the HITS.

Is there a way to make the counter work with links to the detailed view?

Please don't tell me to put the URL to the detailed "$rec{$db_key}$build_extension" in the URL section of the admin when adding a link. I am looking for a real solution like perhaps some Jump.CGI changes or something.

------------------
TheByrdMan Out!

//-Tweet-\\

[This message has been edited by TheByrdMan (edited May 18, 1999).]
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
The idea is to count a hit only when the link to the resource in question is clicked on, not when the detailed page is viewed. It would count the hit exactly the same way as it would if detailed is not used.

The link to the resource on the detailed page should contain the <a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a> link.

This is the way it works by default. Since you do not want to use it this way, you will have to modify jump.cgi. Perhaps this would do it for you. Find the following code in sub main:

Code:
# Let's get the URL.
open (URL, "<$db_url_name") or
&error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL> ) {
(/^$id$delim(.+)/o) or next;
chomp ($goto = $1);
last;
}
close URL;
$goto or &error ("Can't find link id: $id");

Change it to:

Code:
# Let's get the URL.
open (DB, "<$db_links_name") or
&error ("unable to open database: $db_links_name. Reason: $!");
while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec = &split_decode($_);
if ($id eq $rec[0]) {
$goto = "$build_detail_url/$rec[0]$build_extension";
last;
}
close DB;
$goto or &error ("Can't find link id: $id");

I hope this helps.

[This message has been edited by Bobsie (edited May 18, 1999).]
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Thanks Bobsie for the suggestion but I was getting some ugly error messages with that one. It did inspire my resolution though. Here it is:

Code:
# Let's get the URL.
open (URL, "<$db_links_name") or ;
&error ("unable to open url database: $db_links_name. Reason: $!");
while (<URL> ) {
chomp ($goto = "$build_detail_url/$id$build_extension");
last;
}
close URL;
$goto or &error ("Can't find link id: $id");
The above works great. Thanks again.

------------------
TheByrdMan Out!

//-Tweet-\\


[This message has been edited by TheByrdMan (edited May 19, 1999).]
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
This doesn't seem to work here - am I missing something perhaps ?

------------------
Craig Antill
10 Tenths Motorsport (1.1) - www.Ten-Tenths.com/links/
THE Directory (2.0b3) - www.gardenbuildings.com/
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Craig,

I dunno. TheByrdMan never said what the "ugly" error messages were that he was getting so I just left it alone since he had a fix that seemed to work for him. The only thing I see in my code that might need changing is to use $rec{'ID'} instead of $rec[0]. Other than that, it should work.

His code doesn't even check to make sure a valid ID was even in the database to begin with, so the call to sub error in $goto or &error will never occur, even if there was no such ID.

Actually, I did find another error in my code. I forgot to include a "}" to end the "if" statement. The corrected code should be this:

Code:
# Let's get the URL.
open (URL, "<$db_links_name") or
&error ("unable to open database: $db_links_name. Reason: $!");
while (<URL> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec = &split_decode($_);
if ($id eq $rec{'ID'}) {
$goto = "$build_detail_url/$rec{'ID'}$build_extension";
last;
}
}
close URL;
$goto or &error ("Can't find link id: $id");

I hope this helps.

[This message has been edited by Bobsie (edited May 29, 1999).]
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
I checked your links page and found that the links where going directly to the URL rather than the JUMP.CGI. The jump.cgi has the programming that will add a "hit" to a link then send the viewer to the URL in that record. In order to get the above to work you need to make sure you LINK is pointing to the JUMP.CGI like this:
Code:
<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">
and then make no changes to you JUMP.CGI to count up hits to links, or make the suggested changes from Bobsie's or my replies above to make it count up when linking to the detailed view.

Hope this helps.

------------------
TheByrdMan Out!

//-Tweet-\\
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Thanks Bobsie - that seems to works like a charm! (although i'm unable to verify that it's actually incrementing the counter due to the multi-count blocker built in to it!)

TheByrdMan,
Thanks, but you're looking in the wrong place! This is a new section i'm talking about - that is an old install of 1.1 - which incedently does use jump.cgi - it's just been masked with a Javascript mouseover call...

Cheers!

------------------
Craig Antill
10 Tenths Motorsport (1.1) - www.Ten-Tenths.com/links/
THE Directory (2.0b3) - www.gardenbuildings.com/
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
 
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Can someone please tell me why I get the results below when I use the following:

<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}"><%Title%></A>

The url result:

http://www.myurl.com/ads/Children/$build_jump_url?$db_key=$rec{$db_key}

The error:

Not Found
The requested URL /ads/Children/$build_jump_url was not found on this server.
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
It looks like you are using templates. The above code examples are for use with the SITEHTML.PL (or whatever the PL file is called... it's been a while). I'm not sure how you would do this with templates.

------------------
TheByrdMan Out!

//-Tweet-\\
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Yes, I am using templates.

Can anyone suggest a way to workaround this? I need a way to increment the hit counter accessing only detail pages.

Thanks!
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
You've got the mod done and all you need is the link code, right? Take a good look at this now, it's the same as the ORIGINAL jump.cgi HTML found in your link.html template!

change:
<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}"><%Title%></A>

to:
<a class="link" href="<%build_jump_url%>?ID=<%ID%>"><%Title%></A>
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Okay, I tried this mod on Links 2.0 using templates. But the link codes (to link to the detail page) given here don't seem to work at all. Junko's gives me the following error: "Unkown Tag: build_jump_url" for each link. Bobsie's gives me same as Andrew got.

Any have this working on templates? How? Code please.
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Junko... Have you done this with templates?

I get the following when using the hack to jump.cgi posted by Bobsie (the corrected version). I assure you that both the link and detailed page are there.

The url result:
http://www.myurl.com/cgi-bin/ads/jump.cgi?ID=20

The error:
Error: Can't find link id: 20


--
As an aside, up to now, I've used detail.cgi (by widgetz) for any detailed pages. Ideally, I'd like to link to that instead of an actual detailed page. But first I want/need to work out this issue.
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
To be honest I hadn't tried the mod when I wrote that post... but:

Yes I did get it to work but I had to screw around with the code. I had to take out the part that checked the ID before sending it to the URL.

try it: ucmd.virtualave.net/cgi-bin/music/jump2.cgi?ID=345

here's what mine looks like:
Code:
# Let's get the URL.
open (URL, "<$db_links_name") or
&error ("unable to open database: $db_links_name. Reason: $!");
while (<URL> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec = &split_decode($_);
$goto = "http://ucmd.virtualave.net/cgi-bin/music/detailed.cgi?ID=$id";
last;
}
close URL;
$goto or &error ("Can't find link id: $id");

--Drew

[This message has been edited by junko (edited February 03, 2000).]
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Thanks, junko. That indeed made a difference. I'm not sure what impact removing that part of code will have on the operation, but it appears to work (which is all I want).

Now to see if I can somehow get it to use detail.cgi... (let me know if you get that working, too!) :-)
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
The downside(?) is that when a user tries to access a details page for a link that doesn't exist, instead of getting an error, they are just sent back to your main page. But I don't really see anyone trying to manually type in the URL so I don't think it really matters.

If you look at my $goto, I am using it with detailed.cgi w/o any problems.

--Drew
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
I've done this hack too, which works fine (thanks so much!), but now I'm coming up with an interesting problem:

I can't get random links or the site of the day mod to work, probably because I don't have a url in the URL field, and it appears that those functions are trying to look up the url in the url.db

I'm just pointing to the detailed pages, which I've hacked to go into their own categories as well.

Since there is a way around the URL for the jump links, is there a fix for random links or other scripts which rely on opening the url.db?

Thanks,
TigerLily Smile
Quote Reply
Re: How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Is there anyway to make this work on both the url and the detailed page?Unsure
Quote Reply
Re: [LILHOMIE] How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
Ok I can make the count go up but I am having trouble with another part. Instead of ID I want ot go to the Site Title.html. It workds with the ID but not the Site Title. here the code of the counter cgi.

#!/usr/local/bin/perl
# -------------
# Links
# -------------
# Links Manager
#
# File: jump.cgi
# Description: Increments the number of hits for the specified link,
# and sends the user off to the appropriate page.
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 2.01
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================
#
# Form Input:
# '$db_key' = key number # Send as form input the key name and key value
# # of the link you want to go to.
#
# Setup:
# 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";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n[/url]";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
}
# ========================================================
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 {
# --------------------------------------------------------
my %in = &parse_form();
my ($goto, $id, $delim, $time);

$id = $in{$db_key};
$delim = quotemeta($db_delim);
$time = time();




# Pull out the total number of links.
open (COUNT, "<$db_hits_path/index.count") or &error ("unable to open index count file: $db_hits_path/index.count. Reason: $!");
$count = int <COUNT>;
close COUNT;
{
# Bump the counter one.
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 ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT, 2) or &error ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT "$count\n$time\n@IP";
close HIT;
}
}
else {
open (HIT, ">$db_hits_path/$id") or &error ("Can't increment counter file. Reason: $!");
print HIT "1\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;
}

}

my $_file = $id.$build_extension;
print "Location: $build_detail_url/$_file\n\n" ;
exit;
# Now let's send the user to the url..
$goto ?
print "Location: $build_detail_url/$rec{'Title'}$build_extension\n\n" :
&error ("Record not found ($in{$db_key})");
}
sub error {
# ------------------------------------------
#
print "Content-type: text/plain\n\n";
print "Error: $_[0]\n";
exit;
}


the part that I need help with is in bold. So now how what code do I use for the site tile.html to work? I have tried $rec{"Title'}, but received a 404 error. But with $id, it works and goes to $id. html, but I have my script set up to go to sitetitle.html for detailed pages. Please help.Frown
Quote Reply
Re: [LILHOMIE] How can I make the Hit count go up when the user clicks the link to the DETAILED view In reply to
I new if I searched long enough like all day, I would find the answer. Crazy right here. http://www.gossamer-threads.com/...ing=jump.cgi#p112466