• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

jump.cgi

Where can I find a decent, free cgi for redirecting clicks on links?  Something like jump.cgi?ID=x

How do these work, is it founded on a database?
0
Bob3975
Asked:
Bob3975
  • 14
  • 8
  • 6
  • +1
2 Solutions
 
Bob3975Author Commented:
I'm not really familiar with Perl so ths might explain the following statements and questions.  I've already done a redirect with forms but need jump.cgi?ID=x.

http://www.hotscripts.com/Detailed/897.html seems to be Unix only, I need MS Windows.
http://forums.devshed.com/t51481/s.html: what do I do with it?  How do I use it?
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Redirection/: not sure what I'm looking for there.
http://ron28.hypermart.net/redirect/redirect.txt: Uses a form with submit()
0
 
ahoffmannCommented:
could you please explain what exactly you mean with "jump.cgi?ID=x"
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
Bob3975Author Commented:
0
 
ahoffmannCommented:
then jump.cgi maps the ID 3052 to an URL, this mapping could be a database
0
 
Bob3975Author Commented:
Is this something that is available for free/  If so where?
0
 
TintinCommented:
There's probably plenty out there, although it's easy enough to write one.  Here's one that's 100% free for you to use:

Assume the url.db has something like

100,http://www.example.com/page1.html
101,http://www.example.com/page2.html
etc

Then jump.cgi would be:

#!/usr/bin/perl
use strict;
use CGI;

my $urldb="/path/to/url.db";   # File with ID's and URL's

my $q = new CGI;
my $ID = $q->param('ID');
open URLDB, $urldb or die "Can not open $urldb $!\n";

while (<URLDB>) {
  my ($id,$url) = split(/,/);
  if ( $id eq $ID ) {
      print $q->redirect($url);
      exit;
  }
}

print $q->header;
print $q->h1("$ID not found");
0
 
ahoffmannCommented:
> Is this something that is available for free/  If so where?
there're countless solutions doing this, depends on your requirements which one satisfies your requirements
0
 
Bob3975Author Commented:
So cgi is interpretive.  I place that code in a txt file, name it jump.cgi, place it in the cgi-bin directory on the servercreate something like an Access DB with the columns as you show above, and my link would be a link to ../cgi-bin/jump.cgi ?ID=x, right?
0
 
ahoffmannCommented:
i.g. yes
but depends on the web-server, OS, etc. etc.
0
 
Bob3975Author Commented:
The server is a windows server, probably the 2003 version.  The layout of the site has the html in the www/htdocs directory.  The cgi-bin directory is at www/cgi-bin.  I created a text file called txt.db with the format suggested above by Tintin ...

    100,http://www.example.com/page1.html
    101,http://www.example.com/page2.html

just to give my site a name, call it www.example.com.  If my link is defined as ../cgi-bin/jump.cgi?101, the browser tries going to www.example.com/cgi-bin/jump.cgi?101 and I get a 404 error.  If my link is http://www.example.com/../cgi-bin/jump.cgi?101 I get "The system cannot find the file specified. "  Any suggestions?

0
 
TintinCommented:
I'm assuming you are running IIS on your Windows server, in which case, you'll need to enable CGI.

Assuming you have ActiveState Perl installed, open the Documentation and click on the "Web Server Config" link in the left hand frame.
0
 
Bob3975Author Commented:
I'll need to contact my hosting company, but I would have thought that it was already set up that way.
0
 
TintinCommented:
On a lot of Windows webservers, you need to use a .pl extension on Perl scripts.  Try renaming jump.cgi to jump.pl and placing it in an area that you know is accessable.
0
 
Bob3975Author Commented:
I'll try either later tonight or tomorrow.  However this came back from my hosting co,

www.example.com/cgi-bin/jump.cgi?101 should be correct but I also get a 404
error.
I've sent a ticket up to our engineers to see if there are any problems with
permissions.  We will notify you when we get a response back from them.
0
 
TintinCommented:
If you get a 404 error, that means the file/script is not found.  Did you create the cgi-bin directory?

Have you tried renaming to jump.pl and putting it in your web doc root?
0
 
Bob3975Author Commented:
Just about got it.  I got "Not Found" after changing it to a .pl and the host made a fix on their end.  I know the url exists.  But it obviously found the file.
0
 
TintinCommented:
How do you conclude it found the script if you get a "not found" error?
0
 
Bob3975Author Commented:
It's not the 404 error, but the statement from your script...

print $q->header;
print $q->h1("$ID not found");

try http://www.promonmc.com/cgi-bin/jump.pl?100.

The contents of the file txt.db is...
100,http://www.promonmc.com/catalog/P084hi.htm
101,http://www.promonmc.com/catalog/bags.htm

I altered the script to be...
#!/usr/bin/perl
use strict;
use CGI;

my $urldb="txt.db";   # File with ID's and URL's

my $q = new CGI;
my $ID = $q->param('ID');
open URLDB, $urldb or die "Can not open $urldb $!\n";

while (<URLDB>) {
  my ($id,$url) = split(/,/);
  if ( $id eq $ID ) {
      print $q->redirect($url);
      exit;
  }
}

print $q->header;
print $q->h1("$ID not found");
0
 
Bob3975Author Commented:
It's not the 404 error, but the statement from your script...

print $q->header;
print $q->h1("$ID not found");

try http://www.promonmc.com/cgi-bin/jump.pl?100.

The contents of the file txt.db is...
100,http://www.promonmc.com/catalog/P084hi.htm
101,http://www.promonmc.com/catalog/bags.htm

I altered the script to be...
#!/usr/bin/perl
use strict;
use CGI;

my $urldb="txt.db";   # File with ID's and URL's

my $q = new CGI;
my $ID = $q->param('ID');
open URLDB, $urldb or die "Can not open $urldb $!\n";

while (<URLDB>) {
  my ($id,$url) = split(/,/);
  if ( $id eq $ID ) {
      print $q->redirect($url);
      exit;
  }
}

print $q->header;
print $q->h1("$ID not found");
0
 
ahoffmannCommented:
is txt.db located in the same directory as jump.cgi?
If not, use a full path.
Also use
   open URLDB, "<$urldb" or die "Can not open $urldb $!\n";
instead of
   open URLDB, $urldb or die "Can not open $urldb $!\n";

And is you still get errors, try debugging using this

  open URLDB, "<$urldb" or do { print "Can not open $urldb $!\n"; exit 0; }
0
 
Bob3975Author Commented:
I gotta learn perl!  I put in 'open URLDB, "<$urldb" or do { print "Can not open $urldb $!\n"; exit 0; }' that ahoffmann suggested and got...

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

syntax error at D:\vol\promonmc.com\www\cgi-bin\jump.pl line 11, near ") {"
syntax error at D:\vol\promonmc.com\www\cgi-bin\jump.pl line 17, near "}"
Execution of D:\vol\promonmc.com\www\cgi-bin\jump.pl aborted due to compilation errors.

0
 
ahoffmannCommented:
damn, missed the closing ;
  open URLDB, "<$urldb" or do { print "Can not open $urldb $!\n"; exit 0; };
0
 
Bob3975Author Commented:
It's not finding $ID.  I altered the source to be...
------------------------------------
#!/usr/bin/perl
use strict;
use CGI;

my $urldb="txt.db";   # File with ID's and URL's

my $q = new CGI;
my $ID = $q->param('ID');
open URLDB, "<$urldb" or do { print "Can not open $urldb $!\n"; exit 0; };

print $q->header;
print $q->h1("here1");
while (<URLDB>) {
  my ($id,$url) = split(/,/);
print $q->h1($id, " - ", $ID);
  if ( $id eq $ID ) {
print $q->h1("here3");
      print $q->redirect($url);
      exit;
  }
}

print $q->h1("here4");
print $q->h1("$ID not found");
------------------------------------

The url I used is http://www.promonmc.com/cgi-bin/jump.pl?100

It returns...
here1
100 -
101 -
here4
not found
0
 
Bob3975Author Commented:
I'm going to increase the points since I'm requiring an unusual amount of hand holding.
-----------------------
If the code reads ...
while (<URLDB>) {
  my ($id,$url) = split(/,/);
  if ( $id eq $ID ) {
      print $q->redirect($url);
  }
}
print $q->header;
print $q->h1("$ID not found");

I get HTTP 404 - File not found
-----------------------
If it reads...
while (<URLDB>) {
  my ($id,$url) = split(/,/);
  if ( $id eq $ID ) {
print $q->header;
print $q->h1($url);
      exit;
  }
}
print $q->header;
print $q->h1("$ID not found");

I get http://www.promonmc.com/
------------------------
txt.db contains...
100,http://www.promonmc.com/
101,http://www.promonmc.com/catalog/bags.htm/
------------------------
the url used is ...
http://www.promonmc.com/cgi-bin/jump.pl?ID=100
0
 
ahoffmannCommented:
as your posted data does not contain what jump.pl wrote (H1 tag), I assume that the redirect worked
then you get the 404 error from the other server

or your jump.pl has not been called at all, then check your server's logfiles
0
 
TintinCommented:
Change the code to:

while (<URLDB>) {
  my ($id,$url) = split(/,/);
  if ( $id eq $ID ) {
      chomp $url;
      print $q->redirect($url);
  }
}
print $q->header;
print $q->h1("$ID not found");

The chomp is needed to remove the end of line character/s from the url.
0
 
Bob3975Author Commented:
Thanks guys!  On my todo list...learn perl.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 14
  • 8
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now