Bob3975
asked on
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?
How do these work, is it founded on a database?
ASKER
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()
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()
could you please explain what exactly you mean with "jump.cgi?ID=x"
ASKER
An example would be http://url/cgi-bin/search1/jump.cgi?ID=3052.
then jump.cgi maps the ID 3052 to an URL, this mapping could be a database
ASKER
Is this something that is available for free/ If so where?
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");
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");
> 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
there're countless solutions doing this, depends on your requirements which one satisfies your requirements
ASKER
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?
i.g. yes
but depends on the web-server, OS, etc. etc.
but depends on the web-server, OS, etc. etc.
ASKER
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?
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?
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.
Assuming you have ActiveState Perl installed, open the Documentation and click on the "Web Server Config" link in the left hand frame.
ASKER
I'll need to contact my hosting company, but I would have thought that it was already set up that way.
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.
ASKER
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.
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.
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?
Have you tried renaming to jump.pl and putting it in your web doc root?
ASKER
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.
How do you conclude it found the script if you get a "not found" error?
ASKER
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");
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");
ASKER
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");
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");
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; }
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; }
ASKER
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\cg i-bin\jump .pl line 11, near ") {"
syntax error at D:\vol\promonmc.com\www\cg i-bin\jump .pl line 17, near "}"
Execution of D:\vol\promonmc.com\www\cg i-bin\jump .pl aborted due to compilation errors.
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\cg
syntax error at D:\vol\promonmc.com\www\cg
Execution of D:\vol\promonmc.com\www\cg
damn, missed the closing ;
open URLDB, "<$urldb" or do { print "Can not open $urldb $!\n"; exit 0; };
open URLDB, "<$urldb" or do { print "Can not open $urldb $!\n"; exit 0; };
ASKER
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
--------------------------
#!/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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
-----------------------
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys! On my todo list...learn perl.
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Redirection/
http://forums.devshed.com/t51481/s.html
http://ron28.hypermart.net/redirect/redirect.txt
http://www.hotscripts.com/Detailed/897.html