PDA

View Full Version : header problem



munkynpunky
12-13-2006, 11:57 AM
Hi guys,

I think my script is right but my host say its wrong...

can you find an issue?



$URL='QUERY_STRING';

<p>The query string is: <?php echo $_SERVER[$url]; ?></p>

<p>Filename: <? echo $_GET['filename'] ?></p>
$url="www.en4cer.co.uk/downloads/".$url
header ("Location: $URL");

<html>
<title>Ades Design</title>
<head></head>
<body>
</body>
</html>

Twey
12-13-2006, 01:15 PM
I can find several.
$URL='QUERY_STRING';This code is outside a PHP block, so will be printed, not executed. Also, setting it to the static value 'QUERY_STRING' seems useless to me. I would suspect that you meant $_SERVER['QUERY_STRING'].
<p>The query string is: <?php echo $_SERVER[$url]; ?></p>Variable names are case-sensitive. You defined $URL, not $url. The paragraphs are also outside an HTML body.
<p>Filename: <? echo $_GET['filename'] ?></p>You haven't actually done anything with this, but it sounds dangerous, since it implies that you're going to allow the client to pass you a filename without doing any validation on it.
$url="www.en4cer.co.uk/downloads/".$urlHere you define $url, but since $url currently isn't defined, $url is 'www.en4cer.co.uk/downloads/'. Since it's to be passed as a header, this should be a full URL, including protocol. Also, you missed a semicolon.
header ("Location: $URL");Equivalent to:
header ('Location: QUERY_STRING');
<html>
<title>Ades Design</title>
<head></head>
<body>
</body>
</html>No DOCTYPE was provided, the title should be inside the head, and you're still in PHP parsing mode. Also, this code will never (or should never) be read. I suppose it's not a bad idea to provide something for unusual clients, though, even if those clients don't support HTTP fully.
<?php
$url = 'http://www.en4cer.co.uk/downloads/' . $_SERVER['QUERY_STRING'];
header("Location: $url");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Ades Design</title>
</head>
<body>
<p>
Warning: your browser does not support
HTTP correctly. It is likely that a large portion
of the Web will be broken for you.
</p>
<p>
You should have been sent to <a href="<?php print $url; ?>"><?php print $url; ?></a>.
</p>
</body>
</html>

munkynpunky
12-13-2006, 01:35 PM
ah, hang on....

Ok, the script is



<?
$URL='QUERY_STRING';

<p>The query string is: <?php echo $_SERVER[$url]; ?></p>

<p>Filename: <? echo $_GET['filename'] ?></p>
$url="www.en4cer.co.uk/downloads/".$url
header ("Location: $URL");
?>
<html>
<title>Ades Design</title>
<head></head>
<body>
</body>
</html>

this document is called downloads.php, and i go to downloads.php?file=8

Twey
12-13-2006, 01:43 PM
It's still wrong. Use the one I posted above.
header ("Location: $URL");I forgot to mention that this won't work, since you've already sent output.

munkynpunky
12-13-2006, 02:21 PM
Created a new document using your template above, but it doesnt work.. http://www.en4cer.co.uk/downloads2.php?file=8

Twey
12-13-2006, 02:31 PM
It was a complete script, not a template. Nevertheless, are you certain there was no whitespace before the opening <?php? If there were, the script would fail to work.

mwinter
12-13-2006, 02:32 PM
I suppose it's not a bad idea to provide something for unusual clients, though, even if those clients don't support HTTP fully.

There are some lingering HTTP/1.0 user agents, so yes, the HTTP/1.1 recommendations should be followed and certain redirections should be accompanied by a hypertext link. It's not that difficult: the markup you posted could be included in an include file. However, one should avoid mentioning technical details - especially when what you've written isn't necessarily correct :) - and just request that the user follow the link.

Mike

munkynpunky
12-13-2006, 02:37 PM
It was a complete script, not a template. Nevertheless, are you certain there was no whitespace before the opening <?php? If there were, the script would fail to work.

sorry, i meant script.. :) deff no white space, certain

Twey
12-13-2006, 02:52 PM
There are some lingering HTTP/1.0 user agentsSurely they don't send an Host header, and so are completely broken on the Web of today?
deff no white space, certainNo text of any kind? No linebreaks, spaces, tabs, DOCTYPEs?

mwinter
12-13-2006, 03:07 PM
Surely they don't send an Host header, and so are completely broken on the Web of today?

No, not all. Some implemented the Host header as an extension so they can just about manage. NN4, for example.

Mike

munkynpunky
12-13-2006, 03:13 PM
nothing,

this is a copy/paste


<?php
$url = http://www.en4cer.co.uk/downloads/' . $_SERVER['QUERY_STRING'];
header("Location: $url");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Ades Design</title>
</head>
<body>
<p>
Warning: your browser does not support
HTTP correctly. It is likely that a large portion
of the Web will be broken for you.
</p>
<p>
You should have been sent to <a href="<?php print $url; ?>"><?php print $url; ?></a>.
</p>
</body>
</html>

Twey
12-13-2006, 03:51 PM
Ah! I apologise. I missed a single quote (') before http: on the second line. I've edited the original.

munkynpunky
12-13-2006, 04:25 PM
hmm, ok thats not worked..

basically what happens is

on the website, it shows the name of the download then the amount of downloaded times...

ie.. DOWNLOAD1 - 5641

you click on DOWNLOAD1 and it takes you to a promt to enter a word..

once you enter the work it takes you to the actual file and starts the download

everything works up until the locating the file..