Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2004
    Posts
    6

    Angry Unanswered: redirect to an html page

    hello..i am hoping there is someone out there who can answer my question...

    here is what i am doing..i have a serious of forms which are collecting information...once all of the information is collected the user clicks the submit button which runs 2 different programs on the server...

    here is where my question comes in...when those 2 programs are completed i want to redirect the user to a different webpage...how do i do that?

    so my command to run the server program looks like so

    system("nsga2");

    now what do i put after this to redirect the user to my email.htm page AFTER the programs are complete!

    thanks!

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    I assume you are using CGI. Then it is very simple:
    Code:
    #! /usr/bin/perl
    use strict; # to avoid misspellings and sth. like this
    use warnings; # to get additional warnings
    use CGI; # to use CGI
    use CGI::Carp qw(fatalsToBrowser); # to display warnings and errors on the browser
    
    my $cgi = CGI->new(); # create an instance of CGI
    print $cgi->redirect(-url => 'http://domain.tld/my_site.html'); # redirect to my page
    
    system("program parameters ..."); # start a program
    board.perl-community.de - The German Perl-Community

  3. #3
    Join Date
    Mar 2004
    Posts
    16
    U can simply use
    get or post method of html
    to redirect to next page.

  4. #4
    Join Date
    Mar 2004
    Posts
    6
    Originally posted by reneeb
    I assume you are using CGI. Then it is very simple:
    Code:
    #! /usr/bin/perl
    use strict; # to avoid misspellings and sth. like this
    use warnings; # to get additional warnings
    use CGI; # to use CGI
    use CGI::Carp qw(fatalsToBrowser); # to display warnings and errors on the browser
    
    my $cgi = CGI->new(); # create an instance of CGI
    print $cgi->redirect(-url => 'http://domain.tld/my_site.html'); # redirect to my page
    
    system("program parameters ..."); # start a program
    Thanks for the above code...but i want to redirect them to the new page AFTER i run the system command...so would i just cut the "print..." line and put it after the "system" command?

    jess

  5. #5
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    Originally posted by jlm661
    Thanks for the above code...but i want to redirect them to the new page AFTER i run the system command...so would i just cut the "print..." line and put it after the "system" command?

    jess
    the redirect-command is executed after all other commands in the programm, so you could use the code as it is...
    board.perl-community.de - The German Perl-Community

  6. #6
    Join Date
    Mar 2004
    Posts
    6

    not working

    Originally posted by reneeb
    the redirect-command is executed after all other commands in the programm, so you could use the code as it is...
    okay here is my code:

    ___________________________________________-
    #!/usr/bin/perl -wT

    use CGI;



    $ENV{'PATH'} = '/usr/sbin:/usr/bin';

    print "Content-type: text/plain\n\n";

    my $cgi = CGI->new();
    print $cgi->redirect(-url => 'http://www.yahoo.com');
    # create an instance of CGI

    $dir = "/home/edog.1/jlm661/nsga/GA/";
    chdir $dir or die "Can't cd to $changedir: $!";
    print "changed dir okay\n";

    $result2 = system("./deviation1");
    if ($result2)
    {
    print "Error: Couldn't run $result2: $!";
    }
    _____________________________________
    and here is my output:
    _______________________________________
    Status: 302 Moved
    Location: http://www.yahoo.com

    changed dir okay

    Executing GASP for Passenger # 1.0

    GASP IS DONE
    _______________________________________

    what am i doing wrong???

  7. #7
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167

    Re: not working

    You print two different headers: The first time you print a header which say, that the site is a plain text and the second header is the redirect-header. You have to decide, what you want.

    The following code is untested:
    Code:
    #!/usr/bin/perl -wT
    use CGI;
    BEGIN{
      $ENV{'PATH'} = '/usr/sbin:/usr/bin'; 
    }
    my $cgi = CGI->new();
    print $cgi->redirect(-url => 'http://www.yahoo.com'); 
    my $file = './test.txt';
    # create an instance of CGI
    $dir = "/home/edog.1/jlm661/nsga/GA/";
    chdir $dir or print2file("Can't cd to $changedir: $!");
    print2file("changed dir okay\n");
    $result2 = system("./deviation1");
    if ($result2)
    {
    print2file("Error: Couldn't run $result2: $!");
    }
    
    sub print2file{
      my ($message) = @_;
      open(W_FILE,">>$file") or die $!;
      print W_FILE $message;
      close W_FILE;
    }
    you have to create a file, named test.txt and change the rights to 777.

    With that code the user cannot see, whether deviation1 was successful or not but the user is redirected to yahoo.com.
    board.perl-community.de - The German Perl-Community

  8. #8
    Join Date
    Mar 2004
    Posts
    6

    Re: not working

    using your code:

    #!/usr/bin/perl -wT
    use CGI;
    BEGIN{
    $ENV{'PATH'} = '/usr/sbin:/usr/bin';
    }
    my $cgi = CGI->new();
    print $cgi->redirect(-url => 'http://www.yahoo.com');
    my $file = './test.txt';
    # create an instance of CGI
    $dir = "/home/edog.1/jlm661/nsga/GA/";
    chdir $dir or print2file("Can't cd to $changedir: $!");
    print2file("changed dir okay\n");
    $result2 = system("./deviation1");
    if ($result2)
    {
    print2file("Error: Couldn't run $result2: $!");
    }

    sub print2file{
    my ($message) = @_;
    open(W_FILE,">>$file") or die $!;
    print W_FILE $message;
    close W_FILE;
    }[/code]
    ______________________________________

    i got an internal service error. i have never used "print2file" before, does that work just like the open (FILE)...print FILE...close (FILE)???

    thank you so much for your help by the way

  9. #9
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    print2file is a subroutine I defined.
    Please add "use CGI::Carp qw(fatalsToBrowser);" after "use CGI;". Then you should get the errormessage on the browser.
    board.perl-community.de - The German Perl-Community

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •