LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2004, 03:38 AM   #1
@ngelot
Member
 
Registered: Oct 2004
Posts: 84

Rep: Reputation: 15
Help with perl


Hi!

I'm a newbie with perl, and I need help to get started....

I'm trying to make a redirect.cgi.

When somebody click on any of my links, they will be redirected to another page.

Ex.

<a href="xxxx://www.mydomain.org/redirect.cgi?201>Start here!</a>

and a redirect.cgi perl-script that link 201 to mydomain.org/start.html

I've tried some myself, and I understand I need to use if/else in some way.

This is what I have tried, with no luck:

#!/usr/bin/perl

if ( 201 )
then url = "xxxx://www.mydomain.org/start.html"

if ( 202 )
then url = "xxxx://www.mydomain.org/login.html"

exit

:-) I know it's way out, but I think I on th
 
Old 10-27-2004, 04:09 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
try :

for the link add a named variable, say 'id'
<a href="xxxx://www.mydomain.org/redirect.cgi?id=201>Start here!</a>

Code:
#/usr/bin/perl

$id=$ENV{"QUERY_STRING"};
($key, $val) = split(/=/,$id);

if($val == 201) {
    print "Location: http://www.mydomain.org/start.html\n\n";
} elsif ($val == 202) {
    print "Location: http://www.mydomain.org/login.html\n\n";
}

Last edited by Cedrik; 10-27-2004 at 04:10 AM.
 
Old 10-27-2004, 05:39 AM   #3
@ngelot
Member
 
Registered: Oct 2004
Posts: 84

Original Poster
Rep: Reputation: 15
Thanks!

I followed your example....

Called your code redirect.cgi and put it in /var/www/cgi-bin/ and /usr/lib/cgi-bin/

Then I tried it on my web-page with the link:

<a href="xxxx://www.mydomain.org/cgi-bin/redirect.cgi?id=201>Start here!</a>

but the server just returned the cgi-script - eg. the code - not the right page....

I belive I have to do some typing in httpd.conf?

It's already loading cgi_module:

LoadModule cgi_module /usr/lib/apache/1.3/mod_cgi.so

I've also installed (with apt) libapache-asp-perl and typed in httpd.conf:

LoadModule perl_module /usr/lib/apache/1.3/mod_perl.so

and I got no errormessage in return...

What am I doing wrong?

@ngelot
 
Old 10-27-2004, 05:53 AM   #4
@ngelot
Member
 
Registered: Oct 2004
Posts: 84

Original Poster
Rep: Reputation: 15
What's strange too

is that when I click on a invalide link I get a 500 Internal Server Error, and the information returned are wrong.

In httpd.conf I've spesified my webmaster-email and my domain, but the returned error-message say "webmaster@debian" and "Apache/1.3.26 Server at 127.0.0.1 Port 80". It's using the default domain-name....

After editing httpd.conf I run:

apache -f /etc/apache/httpd.conf

and (to be sure):
apache restart

But when entering the site it seems not to use my edited httpd.conf.....

What am I doing wrong?

@ngelot
 
Old 10-27-2004, 07:49 AM   #5
neilman
Member
 
Registered: Oct 2004
Location: Northville, MI
Distribution: Slackware
Posts: 65

Rep: Reputation: 15
You need to configure Apache like this:
Code:
AddHandler cgi-script .cgi
And after the <Directory "/svr/www/htdocs"> (or whever your main htdocs is located), make sure your Options contains ExecCGI.

Here's an example of one I have on an old server of mine -- I have the main htdocs setup to allow for CGIs to be executed, as well as a virtual host:
Code:
<Directory "/usr/local/apache_1.3.26/htdocs">
    Options Indexes FollowSymLinks MultiViews ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
    
<VirtualHost 10.100.1.1>
    ServerAdmin neil@foo.com
    DocumentRoot /home/neil/htdocs
    ServerName neil.foo.com
    ScriptAlias /cgi-bin/ /home/neil/cgi-bin/
    <Location />
        Options ExecCGI
    </Location>
</VirtualHost>
If this still doesn't work for you, just send me a private message with your httpd.conf attached, and I'll make the necessary changes for you and send it back.

Also don't forget to test the syntax of your perl script from your shell prompt. A simple perl -c redirect.cgi should do the trick. If you see syntax OK, your script is good. Just make sure that's good first.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM
can i set ~/public_html/perl as a perl directory for apache? doublefailure Linux - Networking 1 07-09-2002 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration