Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

URL redirection

by Anonymous Monk
on Oct 22, 2007 at 09:05 UTC ( [id://646388]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am developing a small CGI application. My application automatically should open another page(cgi script) once the user is authenticated. I tried the redirect function of CGI

$cgi->redirect(url)

but it is not working for me .
Can anyone help me please ?. Thanks

Replies are listed 'Best First'.
Re: URL redirection
by Corion (Patriarch) on Oct 22, 2007 at 09:17 UTC

    Works for me:

    Q:\>perl -MCGI=redirect -e "print redirect('http://google.de')" Status: 302 Moved Location: http://google.de

    Maybe you didn't print the result from ->redirect? Otherwise, it's always helpful to tell us how exactly things do not work, and maybe tell us the entries in the server error log as well.

      Sorry for insufficient infomation.
      my $username=$cgi->param('username'); if ($username eq 'testuser'){ print $cgi->redirect("http://navitwiki/cgi-bin/main.cgi"); }else{ $message='Please Check the Username & Password'; &init_screen(); }


      this is my code. While running only the following text is displayed . but i want to open the mentioned script in the browser .
      URL Status: 302 Moved Location: http://navitwiki/cgi-bin/main.cgi

        So, the most likely cause is that you or your script output something else before the redirect is printed, because, as you see in the output, the Location: header is there. Run your script on the command line to see what it outputs, or use the GET command from LWP to see what your script outputs:

        GET -USe http://...

        ... or alternatively, debug what is output via telnet.

Re: URL redirection
by siva kumar (Pilgrim) on Oct 22, 2007 at 09:41 UTC
    You might have used print statement before doing CGI redirect. You can also use print "Location: http://www.somewhere.com\n\n";
    or else you can use
    <META HTTP-EQUIV="refresh" content="1;URL=http://www.somewhere.come/">
Re: URL redirection
by snopal (Pilgrim) on Oct 22, 2007 at 13:16 UTC

    If you need to see the output of headers from the CGI you are writing to make sure they conform to your expectations, you can pass your parameters on the command line:

    #> perl mytest.cgi username=myname userid=9999

    Your output is what is sent to the client browser, unless your web server re-interprets your content (some do). If you see anything in the header not matching what a HTML Header should look like, that is likely what is breaking your page.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://646388]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found