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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Header function doesn't work on PHP/4.0.6? 2

Status
Not open for further replies.

smashing

Programmer
Joined
Oct 15, 2002
Messages
170
Location
US
A simple redirect script:

if ($_POST[companyname] == "") {
header ("Location: uploader.html");
exit;

Gets this displayed:

X-Powered-By: PHP/4.0.6 Location: uploader.html Content-type: text/html


???????????
 
There is not much PHP on the page, all there is is this:

<?
if (($_POST[companyname] == &quot;&quot;) || ($_POST[phone] == &quot;&quot;)) {
header (&quot;Location: uploader.html&quot;);
exit;
}
?>
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<html>

from here onwards regular HTML

I take the same file, put it onto a different server (that uses PHP Version 4.2.3 by the way) & everything works fine. Also note that I get the above same message on the 1st machine wether the condition set to redirect is met or not
 
Again, how are you examining that output?

It could be something as simple as the older version of PHP output only &quot;\n&quot; at the end of a header line, rather than the more correct &quot;\r\n&quot;. If the application you are using to examine the output is sensitive to the difference, then it could be something that simple. Does your application allow you to view the output in hexadecimal?

What do you mean by &quot;same message on the 1st machine whether the condition set to redirect is met or not&quot;? I don't understand.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
The condition I've set for the script to look is if people have filled out a text field called 'companyname'.
If they've left that field empty, they should be redirected to another page, so this would usually do it:

if ($_POST[companyname] == &quot;&quot;)
//only then redirect
{
header (&quot;Location: uploader.html&quot;);
exit;
}

but on the server with version 4.0.6, if the script is called , no matter if 'companyname' has been filled out or not all I'll see in the browser(IE 5.0) is always this:

X-Powered-By: PHP/4.0.6 Location: uploader.html Content-type: text/html

I've no idea if and how to get Internet Explorer to view in hexadecimal.
 
PHP 4.0.6 doesn't have [tt]$_POST[/tt]. Change the if to read:
[tt]if ($HTTP_POST_VARS['companyname'] == &quot;&quot;)[/tt]

//Daniel
 
danielhozac
I gave you a star for picking up on this. Really, I should have seen that right away.
 
Thanks to Daniel!!
And To DRJ478 - Don't dish out stars just yet!!
I now get the script to display what I want. But it still throws in this line before the rest of the stuff on the page:

X-Powered-By: PHP/4.0.6 Content-type: text/html.

And in the next script in my sequence (this is part of a 2-step uploading form) I changed 34 instances of $_POST to read $HTTP_POST_VARS but it'll still only displaying the X-Powered-By etc. line.
That script probably violates PHP/4.0.6's rules in many other ways, I'm not posting the whole thing here 'cause it's way too long, I guess I'll just have to switch to a different host with a newer version of PHP.

Thanks as always

 
smashing
The star is for the astute observation of the discrepancy between $_POST and your PHP version, not for solving your particular problem.
Here's another idea:

HTTP 1.1 requires an absolute URI as the argument for the location header. You have only the filename.
The fully compliant way would be:
Code:
header(&quot;Location: [URL unfurl="true"]http://&quot;.$HTTP_SERVER_VARS[/URL]['HTTP_HOST'].dirname($HTTP_SERVER_VARS['PHP_SELF']).&quot;/&quot;.$relative_url);
 
smashing:
Whether or not PHP displays the X-Powered-By custom HTTP header is determined by the php.ini runtime configuration setting &quot;expose_php&quot;.

I don'd know if this is something you wanted to get rid of.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top