Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-07
9
Medium Priority
?
633 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

597 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