Hunting for failing relocate()

Fri 22nd October 2004 20:59 EEST

I got a troubled call from one of our clients explaining that they couldn't create new articles in MidCOM AIS. A few interrogative questions and login to the site proved that the Internet Explorer displayed the much loathed "Page cannot be shown" error - how very useful for debugging. Everything worked perfect with Firefox, so I started to go through the code.

As the server software had been upgraded two days earlier to Midgard 1.6.0rc2 and PHP 4.3.9 I started to doubt that the PHP upgrade might have been to blame. The doubt was further deepened by the fact that the exact same MidCOM packages worked perfect on another server.

The solution, however, was found in one of the MidCOM's core snippets (/midcom/application) and it's function called relocate($url). It is using $_SERVER['HTTP_HOST'] to define the server where it should return the passed URL. The server at question returned www.myserver.com:8001, which was bad since the port was also added later on resulting in a request like "http://www.myserver.com:8001:8001/path/to/the/url". Obviously IE couldn't pass this without complaining. So it's either the PHP's API that has changed or the server's signature and I must say I can't tell which.

So, now I'm wondering should the $_SERVER['HTTP_HOST'] be replaced with $_SERVER['SERVER_NAME'] or use some pattern matching to prevent duplicated port? I used the latter to remedy the client's problem but this may not be suitable for all environments.

NOTE: The article still gets created, it's just the relocation that fails. So, it was possible to create the article, then go back to the topic view and edit the article.