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!

CGI redirect code??

Status
Not open for further replies.

jwoods38

Programmer
Jan 5, 2002
3
AU
Hi everyone, I'm relatively new to Perl and CGI but I'm working on a Perl CGI script at the end of which I want to redirect the user to a new html page. Is there a function to do this. I know it's probably a really newbie question but I'd appreciate any help! Thanks in advance.
 
Hi
use this:

print "Location:your-redirect-url\n\n";

make sure you have \n\n at the end or it will says invalid header


cheer
kevin
 
I think the following is what you're after is something along the lines of:

****

use CGI;
my $query = new CGI();
print $query -> redirect(-location => "myCGI.cgi", -nph => 1);


****


HTH,
Barbie.
Leader of Birmingham Perl Mongers
 
Hi Missbarbell,
your line is just equivalent to my code... the internal working of the CGI.PM will use my code, and nph->1 just tell the server not to parse the header... so why waste time initilize the variables of the CGI object?

cheer
kevin
 
Hey guys thanks,
They both work normally, however for my page to display html I have to use the line Content-type: text/html and this prints everything in HTML. Is there a way to turn this printing in HTML off? Thanks again.
 
well,
you can set the header to something else depend on what you want to print.. here is a shortlist

text/plain: Plain text.
text/html : HTML files.
text/richtext: Rich Text Format.
image/gif : GIF images
image/jpeg : JPEG images
image/x-xbitmap X bitmap is a very simple pixel-by-pixel description of images.
audio/basic: Basic 8-bit, ulaw compressed audio files.
audio/x-wav: Microsoft Windows audio format.
video/mpeg: MPEG compressed video.
video/quicktime: Quicktime video.
video/x-msvideo: Microsoft Video. Usually ends with the extension .avi.
application/octet-stream
application/postscript: Postscript files.

I believe there are some more but i don't remember
cheer
kevin
 
For a full list of mime types, on a *nix system have a look for the file mime.types, usually under /etc. Though there are sites online which list them too.

Barbie Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top