Solved

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

Posted on 2008-10-07
9
582 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php documentation 4 21
php connect() failed error 25 16
Web Reply Form - PHP with Upload 4 20
Insert data into database 2 15
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The viewer will learn how to dynamically set the form action using jQuery.

758 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

17 Experts available now in Live!

Get 1:1 Help Now