Solved

PHP 4.4.9, on IIS6, Header(Location:...) doesn't work

Posted on 2008-10-07
9
601 Views
Last Modified: 2013-12-13
Hello,

Recently we transfered a web-application (PHP 4.4.9) from a Linux/Apache to a Win2003/IIS6 webserver. Now we've noticed a problem with pages containing a Header(Location:...) statement, instead of being redirected to the specified link, some users get "Page cannot be displayed error". The links in the Header statement aren't fully qualified urls most of the time. We've only noticed the problem with IE browsers. Some users (with IE) don't have the problem at all.

I've asked a colleague of mine, to give me some information using the tool Charles, but when the tool is active, the problem disappears, only the return when Charles is turned off. I noticed at difference between IE and Firefox, using Charles. The response header of such a page, contains "HTTP/1.1 302 Moved Temporarily" when using IE and "HTTP/1.1 302 Found" when using Firefox.

I'm hoping this behavior sounds familiar to someone, since the problem is really blocking a lot of our customers.

Best regards,
Wim Hoskens.
0
Comment
Question by:ecomaster
  • 4
  • 4
9 Comments
 

Author Comment

by:ecomaster
ID: 22661768
Extra note, I'm using the isapi plugin.
0
 
LVL 29

Expert Comment

by:fibo
ID: 22663695
Just a stupid question: since the problem is on relative URLs, can't you make all of them absolute? This would make your script more robust...
You can find the current base within PHP:
see http://www.php.net/manual/en/reserved.variables.server.php
You could then have
$mybase= 'http://' + $_SERVER['SERVER_NAME'] + $_SERVER['SCRIPT_NAME'];

and use that for your Location
0
 

Author Comment

by:ecomaster
ID: 22668573
Thanks for the response.
I've tried this, specifying absolute URLs. But that didn't work either.

I've made an emergency update for certain pages, by replacing the header statement with a bit of code that I found in this link: http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Windows/Q_20572327.html?sfQueryTermInfo=1+header+ii+locat+php (bottom) I also didn't use absolute URLs there and it didn't cause any problem.
For some pages, this would require serious rewriting.

I'm still wondering why in some pages the header statement works without a problem and in other it causes the problem I described, but not for all clients/browsers.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:ecomaster
ID: 22670366
Another symptom, when I replace the header statement::

Header(Location:_anUrl_)

with

Header(Refresh: 0, url=_anUrl_)

the redirection works. Can somebody tell me what the difference could be?
0
 

Accepted Solution

by:
ecomaster earned 0 total points
ID: 22723566
I've found that when I change the statement, by adding a space between 'Location:' and the url, the problem no longer exists. This is a strange behaviour though. When the pages were running on the Apache/Linux server, this wasn't a problem. Is this because Apache is intelligent enough to add the space?
0
 
LVL 29

Expert Comment

by:fibo
ID: 22724190
Hmmm is it really Header(Location:_anUrl_) in your script or Header( 'Location:_anUrl_' ) ?
Looking in more details at php page http://www.php.net/header

1 - It refers to page http://www.faqs.org/rfcs/rfc2616 where you can find

<<4.2 Message Headers

HTTP header fields, which include general-header (section 4.5),
request-header (section 5.3), response-header (section 6.2), and
entity-header (section 7.1) fields, follow the same generic format as
that given in Section 3.1 of RFC 822 [9]. Each header field consists
of a name followed by a colon (":") and the field value. Field names
are case-insensitive. The field value MAY be preceded by any amount
of LWS, though a single SP is preferred. Header fields can be
extended over multiple lines by preceding each extra line with at
least one SP or HT. Applications ought to follow "common form", where
one is known or indicated, when generating HTTP constructs, since
there might exist some implementations that fail to accept anything
>>
which is not very clear if a space MUST follow the : or not.

2 - All examples given at http://www.php.net/header have a space after :
3 - This page also says in the notes
<<HTTP/1.1 requires an absolute URI as argument to  Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:

<<?php
/* Redirect to a different page in the current directory that was requested */
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;
?>
>>

So apparently the behaviour you found was "normal" on some browsers. Funny that the space might be a solution to that problem!
 4 - Most probably your headers were previously sent as http/1.0 which accepts relative URLs, while 1.1 does not.
 
0
 
LVL 29

Expert Comment

by:fibo
ID: 24743084
Ecomsater,
you might consider closing this question by allocating points to answer(s), yours included
0
 
LVL 29

Expert Comment

by:fibo
ID: 25979436
This seems to be the right close!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question