Solved

jump.cgi

Posted on 2004-03-22
29
305 Views
Last Modified: 2013-12-25
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
Comment
Question by:Bob3975
  • 14
  • 8
  • 6
  • +1
29 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10651971
0
 

Author Comment

by:Bob3975
ID: 10652231
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10652903
could you please explain what exactly you mean with "jump.cgi?ID=x"
0
 

Author Comment

by:Bob3975
ID: 10652978
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10653103
then jump.cgi maps the ID 3052 to an URL, this mapping could be a database
0
 

Author Comment

by:Bob3975
ID: 10653133
Is this something that is available for free/  If so where?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10653280
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10653346
> 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
 

Author Comment

by:Bob3975
ID: 10653382
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10653417
i.g. yes
but depends on the web-server, OS, etc. etc.
0
 

Author Comment

by:Bob3975
ID: 10653724
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
 
LVL 48

Expert Comment

by:Tintin
ID: 10653850
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
 

Author Comment

by:Bob3975
ID: 10653954
I'll need to contact my hosting company, but I would have thought that it was already set up that way.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10654043
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Bob3975
ID: 10654104
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
 
LVL 48

Expert Comment

by:Tintin
ID: 10654381
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
 

Author Comment

by:Bob3975
ID: 10654573
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
 
LVL 48

Expert Comment

by:Tintin
ID: 10654655
How do you conclude it found the script if you get a "not found" error?
0
 

Author Comment

by:Bob3975
ID: 10654734
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
 

Author Comment

by:Bob3975
ID: 10654738
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10656622
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
 

Author Comment

by:Bob3975
ID: 10657841
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10658595
damn, missed the closing ;
  open URLDB, "<$urldb" or do { print "Can not open $urldb $!\n"; exit 0; };
0
 

Author Comment

by:Bob3975
ID: 10658981
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
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 100 total points
ID: 10659439
0
 

Author Comment

by:Bob3975
ID: 10659794
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10661878
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
 
LVL 48

Accepted Solution

by:
Tintin earned 300 total points
ID: 10661883
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
 

Author Comment

by:Bob3975
ID: 10661992
Thanks guys!  On my todo list...learn perl.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now