PDA

View Full Version : problem redirecting to file


gnznroses
07-13-2005, 12:47 AM
i'm trying to update a CGI file -- a download counter -- so that instead of always redirecting the user to the file automatically (after incrementing the download count) that i can optionally specify that it show an html file that says "click here to start download". cause with sp2 you can't open a new window to this cgi and it redirect, the window just instantly closes. here's what i've got:


first the script does some usual stuff to read the queery string and put the paramaters into variables, which works fine, then i've got this:




if ( $auto ne 0 ){
print "Location: $url\n\n";
}
else{
print "Content-type: text/html\n\n";
print "<html><head><title>Download</title>\n<style type=\"text/css\">\n<!--\nA { text-decoration:none; font-size:8pt; font-family:verdana\n-->\n</style>\n</head>\n<body bgcolor=#dcd5ca text=#685B48 link=#685B48 vlink=#685B48 alink=#685B48 style=\"font-family:verdana\">\n";
print "<center><br>\n<a href=\"$url\">Click here to start download</a>\n</center></body></html>\n";
}



it works fine when i specify auto=0, but now for some reason when it auto-redirects it shows the file as text in the browser. and all code above this has not been modified from the original. someone suggested i set the content type to application/octet-stream before redirecting, but then the browser simply prints out "Location: " thne the url.

can anyone help?

nkrgupta
07-13-2005, 12:15 PM
Just a thought...Instead of using the standard Perl header can't you use html redirection --

print "Content-type: text/html\n\n";
print "<META http-equiv='refresh' content='0;URL=$url'>";
It should redirect the user to $url.

Jeff Mott
07-14-2005, 01:01 AM
Just a thought...Instead of using the standard Perl header can't you use html redirectionDoing this is actually a bad practice that is discouraged [W3C-HTML4] (http://www.w3.org/TR/1999/REC-html401-19991224/struct/global.html#edef-META).

gnznroses, do you mean to say that the text of your script is displayed? Or that the file it redirects to is displayed?

joeframbach
07-14-2005, 03:59 AM
Note. Some user agents support the use of META to refresh the current page after a specified number of seconds, with the option of replacing it by a different URI. Authors should not use this technique to forward users to different pages, as this makes the page inaccessible to some users. Instead, automatic page forwarding should be done using server-side redirects

so we should not use meta redirects because some browsers don't support it? maybe it's just me, but that just seems wrong. although i am all for supporting everyone's browsers, i dont think i've encountered one that didn't support meta redirects.

(sorry for changing the subject)

rwedge
07-14-2005, 05:23 AM
You code looks ok Maybe consider != rather than ne if 0 is to be numeric.
Are you using strict in your script?

If the file appearing in text is the one represented by the value of $url it may not be the Perl script.

Jeff Mott
07-14-2005, 07:34 AM
although i am all for supporting everyone's browsers, i dont think i've encountered one that didn't support meta redirectsThat is because you're not disabled (I assume). Meta refreshes are discouraged because they have accessibility problems. If you're just building a site for yourself or your family then accessibility might not be a big concern, but for anyone who ever plans to work in Web development professionally: businesses and government agencies cannot, by law, discriminate due to a person's disability. Building a site that is not accessible to these people can cause a big problem.

Imagine if a company did not include wheel chair ramps or elevators in their place of business and then use that as an excuse for not hiring an applicant in a wheel chair. It's the same kind of situation. Especially in big businesses that are targets for lawsuits, you will most likely be required to keep your pages accessible. Best to start learning how now.

And regardless if you're required to or not, your pages will be better for it.