Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jump.cgi

Posted on 2004-03-22
29
Medium Priority
?
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 8
  • 6
  • +1
29 Comments
 

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
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.

 

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
 

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 400 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 1200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

636 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