Solved

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

Posted on 2008-10-07
9
587 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now