Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Jump.cgi Directly to Detailed Pages

Quote Reply
Jump.cgi Directly to Detailed Pages
Can some one please tell mw where I went wrong on this code.

It keeps on telling me that "Error No Link Specified"

I want jump.cgi to go directly to the Deatiled page and to count the click.

Here is the code that I'm using on Jump.cgi

---------------------------------------------

#!/usr/bin/perl

# 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 %in = &parse_form();
my ($goto, $id, $delim, $time);

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

if ($id eq "random") {
my ($count, $rand, $find);

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

# Get the random line from the url lookup database.
srand;
$find = 0; $rand = int (rand ($count + 0.5)); ($rand == $count) and ($rand--);
open (URL, "</epoems/Detailed") or &error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL>) {
$find++ == $rand or next;
/\d+$delim(.+)/o or next;
$goto = $1;
last;
}
close URL;
$goto or &error ("Can't find random line: $rand.");
}
elsif (exists $in{$db_key}) {
# Make sure this is a valid looking id.
($id =~ /^\d+$/) or &error ("Invalid id: $id");

# Let's get the URL.
open (URL, "</epoems/Detailed") 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");

# 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;
}
}
else {
&error ("No link specified!");
}

# Now let's send the user to the url..
$goto ?
print "Location: $goto\n\n" :
&error ("Record not found ($in{$db_key})");
}

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

Quote Reply
Re: Jump.cgi Directly to Detailed Pages In reply to
Well firstly you are trying to open a directory using the "Open" command which is wrong. Secondly you are using relative paths which is not good practice. Thirdly the path you are trying to open is not right - you need to be reading from links.db if that is where the detailed URL's are stored.






Paul
Installations:http://wiredon.net/gt/
Support: http://wiredon.net/forum/

Quote Reply
Re: Jump.cgi Directly to Detailed Pages In reply to
First of all thanks for the reply.

There are no outside links in this set-up. Everything is in-house.

I want people directed to the Detalied pages where a poem is located.

Once they view the poem they would have the option of sending said poem as a Cyber Card. I already have the cyber card script set-up, but I need jump.cgi to direct people to the detailed page and I also need jump.cgi to count the hit. I had it set up where it could go directly to the detailed page, bypassing the jump.cgi, until I realized that the hits where not being counted.

Can you please let me know the correct code to make this possible.

Quote Reply
Re: Jump.cgi Directly to Detailed Pages In reply to
This has already been solved.

Try these:

http://www.camelsoup.com/?view=info_jump
http://www.gossamer-threads.com/...ew=&sb=&vc=1

Smile

DT