Gossamer Forum
Home : Products : Links 2.0 : Customization :

Counting Hits off of links.....

Quote Reply
Counting Hits off of links.....
Hi All.

I'll try to explain what I'm trying to do.

At my site http://www.humbee.com/buzz/ I have a section for news. The news is bring pushed to the page through an seprate cgi script running ssi.

Within the news is the ability to click on the title or the [Full Story] and it will take you to that page; located at my local newspapers site.

I have the newspaper added into the database.

What I'd like to be able to do is set it up where each time one of the "news" links are clicked, it increases the [hits] for the given newspaper.

Does that make sense?

i.e.

Times-Standard is SiteID # 3
They presently have: 6 hits.
Times-Standard is located in category:
News_&_Media/Newspapers

Howver, when someone presses on ANY of the "news" links (on my home page) I'd like to be able to have the 'hits' for Times-Standard (ID 3) go up one hit.

Does anybody know how I can accomplish this task?

Many Blessing to all.
JbA

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/
Quote Reply
Re: Counting Hits off of links..... In reply to
Here is the jump.cgi portion of the mod, which you should rename jumpnews.cgi or something like that...
Code:
#!/usr/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.0
#
# (c) 1998 Gossamer Threads Inc.
#
# This script is not freeware! Please read the README for full details
# on registration and terms of use.
# =====================================================================

use 5.004;
use CGI qw(:cgi);
use Fcntl qw(:flock);
use GD;

$linkid = param('ID');
$id = $linkid; # the link that you want to register hit

$url = param('URL');
$goto = $url; # where you want to go

# 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";
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 ($goto, $id, $time);
$time = time();

# 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;
}

# Now let's send the user to the url..
print "Location: $goto\n\n";
}

sub error {
# ------------------------------------------
#
print "Content-type: text/plain\n\n";
print "Error: $_[0]\n";
exit;
}
Now, I think you should be able to enter the headline URL as...
http://www.humbee.com/cgi-bin/jumpnews.cgi?ID=a_valid_link_id&URL=the_actual_url

If you want to check that the Link ID is valid, or include a new field in the submit post form, it will require some more work. Let me know if it works...

[This message has been edited by oldmoney (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Ok, so just upload the code you sent (jumpnews.cgi) then I should be able to hard-code the following into my newsadmin.cgi form. (within the url section of course)

www.humbee.com/cgi-bin/jumpnews.cgi?ID=6&URL

(with the 'URL' being added by the submission form)

Is that right?

Then when someone clicks on any of the links it would automatically add the 'hit' to the SiteID 'hit' count?


Is that the theory here?
(I like to understand what I'm actually doing Wink )

JbA

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/


[This message has been edited by Yokhannan (edited January 02, 2000).]

[This message has been edited by Yokhannan (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Hi John!

Reading what oldmoney and you have written I would say that the answer to your question is correct.

The script should increase the hit to the site by one each time it is clicked on.

------------------
www.nzcid.godzone.net.nz
New Zealand Christian Internet Directory




Quote Reply
Re: Counting Hits off of links..... In reply to
Bare with me... I'm apparently having problems cutting and pasting. :0

This is just a quick and dirty. In your news submission form for the URL field, you would do something like this...

http://www.humbee.com/cgi-bin/jumpnews.cgi?ID=3&URL=http://www.times-standard.com/entry/1999/dec/thur_30/fireworkframe_123099.html

...at least in theory.
Quote Reply
Re: Counting Hits off of links..... In reply to
I just tested... works fine, increments the counter as expected and redirects.
Quote Reply
Re: Counting Hits off of links..... In reply to
btw... know of any way to acquire the code you sent, then being able to put (paste) it into a new file witout it being in one huge long line?

I'm using a TextPad, which usually handles files pretty good... but when I try to cut-n-paste it... well, its just one or two long lines!

(first time I've needed to cut-n-paste something this big from these discussions!)

Smile
JbA

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/
Quote Reply
Re: Counting Hits off of links..... In reply to
I view source and global replace <P> and <BR>... works for me.
Quote Reply
Re: Counting Hits off of links..... In reply to
Awesome!!

I'll give it a try just as soon as I can get this darn code to copy correctly!

Thanks for the time/effort oldmoney!!

So, has anyone seen/tried this one before?

JbA
Quote Reply
Re: Counting Hits off of links..... In reply to
I've never seen a request for this, but it was intriguing so I decided to work on it. Like I said, there are probably 1,001 more elegant ways to do this, and if you have multiple news editors, I would strive towards incorporating the major news sources directly on the submission form with radio buttons or something, eliminating chance of getting the Link ID wrong.

[This message has been edited by oldmoney (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Code:
I've never seen a request for this, but it was intriguing so I decided to work on it.
Thanks!!
And it's always nice to come up with something that hasn't already been done!
Sometimes it seems everything has!!


Code:
if you have multiple news editors, I would strive towards incorporating the major news sources directly on the submission form with radio buttons or something, eliminating chance of getting the Link ID wrong.

Yes, that was the plan!

Again, Thank you!

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/
Quote Reply
Re: Counting Hits off of links..... In reply to
oopss... ignore this post... for now!

[This message has been edited by Yokhannan (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Ok, things aren't working just right....

I hard-coded the 'value' setting for the url (email) within the newsadmin.cgi script with the following:

Code:
http://www.humbee.com/humbee/jumpnews.cgi?ID=3&URL=
('humbee' is also the name of my cgi-bin)

So, when you pull up the newsadmin.cgi page at: ( www.humbee.com/humbee/newsadmin.cgi ) is shows the above code within the URL section.

So, when I went to add the newest days news to it, I simply added

Code:
http://www.times-standard.com/front/1999/dec/fri_31/safeyearframe_123199.html

to the end of the URL section. Therein making the url field
Code:
http://www.humbee.com/humbee/jumpnews.cgi?ID=3&URL=http://www.times-standard.com/front/1999/dec/fri_31/safeyearframe_123199.html

All seems logical at this point.

So, I go ahead and add the Title, and body, then submit it. It allows it and all that stuff.

Ok, when I load up my site ( www.humbee.com/buzz/ ) is shows the newest news with the url of
Code:
http://www.humbee.com/humbee/jumpnews.cgi?ID=3&URL=http://www.times-standard.com/front/1999/dec/fri_31/safeyearframe_123199.html

This seems correct too.

However, when I click on the link, I get 500 Error.

Whelp, this stumped me!

jumpnews.cgi did get transfered in ascii mode (I tried three times)
and it is set at chmod 755

Any thoughts?
JbA


[This message has been edited by Yokhannan (edited January 02, 2000).]

[This message has been edited by Yokhannan (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Make sure that you have the newsjump.cgi exactly correct (I had a problem copying and pasting it myself twice). Here, get my copy at...
http://fantasysportsgamer.com/modjump.txt
It definitely works at my site... the other alternative is that you don't have the Perl GD libraries.

[This message has been edited by oldmoney (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Hummm... Thanks oldmoney... but that didn't work. (although your jumpnews.cgi did look better then mine!)

So, as you stated it must be that I "don't have the Perl GD libraries".


Well, at this point, I'm not sure what to do.
Is that stricly an server admin thing, or something that I can add?

Is there a way to look for it on my server?
Point the script to it? (if it's there, somewhere?)

These "GD libraries" is a new one for me!!

Gezzz.... I feel like I've said "thank you" about a gizzilian times....

But, Thank You! (again)

JbA
Quote Reply
Re: Counting Hits off of links..... In reply to
John:

Sent you an email, but perhaps you're not checking your other domain... anywho, try this, and let me know what happens (better yet, copy and paste from email just to be sure)...
Code:
#!/usr/bin/perl

use 5.004;
use CGI qw(:cgi);
use Fcntl qw(:flock);
use GD;

$linkid = param('ID');
$id = $linkid;                        # the link that you want to register hit

$url = param('URL');
$goto = $url;                          # where you want to go

    print "Content-type: text/plain\n\n";
    print "ID=$id\nURL=$goto\n\n";
Quote Reply
Re: Counting Hits off of links..... In reply to
Without seeing this other CGI script, impossible to answer. The counter is controlled by jump.cgi, specifically the section marked off by
#Bump the counter one...

You won't need to get the URL, since it is presumably given in the story link, but you will have to pass the ID back to (a modified version of) jump.cgi somehow. The question is, how to implement that without messing up the original URL...
Quote Reply
Re: Counting Hits off of links..... In reply to
OK, here are the .txt format of the cgi scripts! Hope they help!

www.humbee.com/temp/newsadmin.txt

And:

www.humbee.com/temp/newsadmin_settings.txt

JbA

Smile btw... you can call them up by going to: http://www.humbee.com/humbee/newsadmin.cgi

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/


[This message has been edited by Yokhannan (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Hi.

Same thing happened.

I got the 500 error.

;(

JbA

[This message has been edited by Yokhannan (edited January 02, 2000).]
Quote Reply
Re: Counting Hits off of links..... In reply to
Well, darn... I had thought that those were standard Perl distribution libraries. I'm sure there is at least another way to do it, but I'll have to think about it some.
Quote Reply
Re: Counting Hits off of links..... In reply to
Ok, thanks.

------------------
John B. Abela
Owner, 4CM
www.4cm.com/
support@4cm.com

Presently working on:
www.humbee.com/