redirecting errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

redirecting errors

Post by DuFF »

Hey, I've been having some trouble using headers to redirect the user to another page. My host is Lycos and I'm using IE6 (if those could be the problem). Heres an example of something that won't work, I've had numerous redirects not work although a couple do, I'm very confused about this. The following code is used to count the number of downloads:

mapdl.php

Code: Select all

<?php
include("header.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="UPDATE files SET downloads=downloads+1 WHERE file='$file'";
$result=mysql_query($query);
mysql_close();
$dlpage = $_SERVER['DOCUMENT_ROOT'] . $file . "/";
$redirect = "Location: $dlpage";
header ($redirect);
?>
An example link to this would be: mapdl.php?file=maps/as_oilrig.bsp. But when I click the link to download it goes to the above page and just stays there and won't redirect the user. Is there anything I'm doing wrong? Any help would be appreciated.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

chec the headers warning thread, as well as searching. there has been a number of threads on this type of thingsince i gothere.


also, you should understand that microsoft has NEVER conformed to w3c. unless you want the site specifically for those that use ie, dl at least one w3c complaint browser. at this point the most popular two are Mozilla ( http://www.mozilla.org ) and opera (http://www.opera.com ).

i suggest mozilla if you only get one because mozilla is opensource and supported by legions of people that are into that because when netscape was on version 2 or 3 they created an opensource project (mozilla) to help speed along the browser egine development, and netscape would borrow engine upgrades.

if it works right in mozilla, then rest assured the issue is ie being non-compliant
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Thanks for the tips, I looked at the header post and realized I had whitespace in my included header.php, that was the problem. Now this brings up another question, how can I make the user download the file being pointed to, not just open it. Right now the download redirects to a .txt file so the text is displayed in the browser. Is there a way to make sure that the file is downloaded instead of displayed?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

only thing i can think of is renaming the extenson to something windows wont recognise (blah.text.thisisafakeextension)
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

It's ok, I've got it working well now. :D
Post Reply