Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting to another page. 2

Status
Not open for further replies.

iaresean

Programmer
Mar 24, 2003
570
ZA
Hey all!

I have a script called login.cgi. In this script is the normal login form etc. The form sends the information back into the login.cgi script and the script then checks the data for validity. If the data is valid then a success message is displayed and the user can click NEXT to continue, if it isn't the form is redisplayed and an appropriate error message is displayed.

However, I don't want it to be like this, I would like the script to redirect the users browser to the appropriate page (e.g. success.html) if the login info is correct. How do I do this?

Any and all help is appreciated.
Sean.
 
you need to send a redirection in the header.
for example (perl code):

Code:
print "Location: [URL unfurl="true"]http://yourdomain/success.html\n\n";[/URL]


(-:
 
I do hope you're using CGI.pm.
Code:
use CGI qw/:standard/;
print redirect('[URL unfurl="true"]http://www.domain.com/success.html');[/URL]
CGI.pm always creates RFC-compliant headers and is always the best choice.

________________________________________
Andrew - Perl Monkey
 
Yep I am using CGI, and loving it.
;-)

Cheers guys!
Sean.
 
It doesn't seem to be working, it just outputs the following:
Status: 302 Moved Location:

Any ideas why? Here is a snippet of my code:
Code:
#!/usr/bin/perl

#$Id$

use CGI qw/:standard/;
use CGI::Session;

require "/usr/bin/adminlangen_web.pl";                                                                             

my $query = new CGI;

my $submit = $query->param('submitlogin');
my $login = $query->param('login');
my $password = $query->param('password');

my %TXT = getstrings();

if($submit){
        if($password eq "test"){
                $session = new CGI::Session(undef, undef, {Directory=>'/tmp'});
                $session->expire('+30m');
                $cookie = $query->cookie(CGISESSID => $session->id);
                print $query->header( -cookie=>$cookie );
                #storing data in the session
                $session->param('username',"$login");
                
                print redirect('[URL unfurl="true"]http://www.google.com');[/URL]
        }
        else{
                loginform();
                
                print "Sorry that information is incorrect, please try again.";
        }
}
else{
        loginform();
}

Any help is greatly appreciated.
Sean.

psa.gif
 
Redirection is part of the http header, so it must be the first and only thing the script prints.

And since you're already using a CGI object, you can just say $query->redirect and don't bother importing all the :standard functions if you're not using them elsewhere.

________________________________________
Andrew - Perl Monkey
 
Damn, that is exactly what I didn't want to hear, albeit the truth.

icrf, or anyone? Do have any recommendations or methods I could use in order to get around this problem?

Thanks alot for ANY help, even if your just telling me its impossible.

Thank you,
Sean.
psa.gif
 
About your other post-header redirect option is to print meta-refresh tags in the html head. It's a bit sloppier of a way to do it, but better ensures browsers won't cache the page.

________________________________________
Andrew - Perl Monkey
 
YEAH!! I solved it myself!!!

Here is how I solved it, for anyone that has run into this problem as well. It is the exact same code as the above, except I switch this line:
Code:
print redirect('[URL unfurl="true"]http://www.google.com');[/URL]
[/color]
With This:
Code:
print <<EOHTML;
Content-type: text/html\n\n
               
                <script language=&quot;JavaScript&quot;>
                        <!--
                        function redirectPage() {
                                window.top.location='../cadmin.html';
                        }
                        -->
                </script>
                
                <HTML>
                <BODY onLoad=&quot;redirectPage()&quot;>
                <CENTER><H2>Please Wait While Loading...</H2></CENTER>
                </BODY>
                </HTML>
EOHTML

I hope this helps someone else out there!


Sean.
psa.gif
 
I was suggesting something more like this, but use what works. Some browsers and some users don't have javascript enabled, so I try not to depend on it to do anything at all.
Code:
<HTML>
  <HEAD>
    <META HTTP-EQUIV=&quot;Refresh&quot; CONTENT=&quot;0;URL=http://www.some.org/some.html&quot; />
  </HEAD>
  <BODY>
    <CENTER><H2>Please Wait While Loading...</H2></CENTER>
  </BODY>
</HTML>
If you can't use CGI.pm's redirect() method because headers are already printed, then there's no reason to print &quot;Content-type: text/html&quot; before the html (the header's already printed, right? If not, use $query->redirect($url);).

________________________________________
Andrew - Perl Monkey
 
The following will load a new page(refresh) after about 10 seconds. It can be used as a redirect from an old server site to the new server site so your old visitors can still find you. Create a web page on the old site pointing to the new site.

Also it can be used as an initial web page welcoming your visitors to your site then an automatic transfer to a second page.

Remove the 1 for 0 delay or immediate refresh.

<META HTTP-EQUIV=&quot;REFRESH&quot;
CONTENT=&quot;10;URL=the-same-or-some-other-web-page-url&quot;>

Also if your web page has an image that keeps getting updated from a web-cam, you can have a page showing that image doing a refresh on it’s self. Each refresh it loads the current copy of the image.

I add the following to web-can pages so that an old picture is not loaded from cache.

<META HTTP-EQUIV=&quot;REFRESH&quot; CONTENT=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>

I place the META tags in side the HEAD tag set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top