Page 1 of 1

Why Would PHP Improperly Resolve a Local URL?

Posted: Fri Mar 30, 2007 6:37 pm
by WebDiego
OK - This has me very, very stumped....

We operate about 20 domains on a leased server.

Code started "breaking" all over the place, where it involved directly accessing other URLs on our sites.

For example:

Code: Select all

echo file_get_contents("http://domain1.com/index.php");
(the application is much more complex, but this is a simple test case that works).

PHP can no longer find files this way (the above returns a 404 - Not found).

But paste that URL in a browser, and it's fine!

After *MUCH* futzing-around for the past three days, we finally figured-out what's going-on.... PHP (only) is resolving http://domain1.com/index.php to http://domain2.com/index.php!!!???

(domain2 is another of our domains on the same server)

This (DNS?) anomaly only affects PHP - <a href="http://domain1.com/index.php"> works just fine.

How can it be that on one domain, on one box, <a href="http://domain1.com/index.php"> resolves correctly, but file_get_contents("http://domain1.com/index.php") resolves to a completely different domain on the same server?

(BTW - Everything after the domain name is preserved. It's only the domain part of the URL that gets transposed by PHP).

I should also add that everything has been working fine for more than a year. The problem only started recently, and our server guy(s) say they've changed nothing?

Thanks in advance for any suggestions.

Posted: Mon Apr 02, 2007 2:40 pm
by WebDiego
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Still no closer to a solution, but I did a little experiment with CURL, which *also* takes me to the wrong domain....

Code: Select all

<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://domain1.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

// display file
echo $file_contents;
?>
As was the case with PHP, the above displays the home page of "domain2," instead of "domain1."

This server (and the domains on it) are all behaving well to the "outside world" via browsers, but it's almost as though internal resolves (PHP and CURL, at least) are using some sort of (corrupt?) local DNS cache, or something.

Any ideas?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]