Relative PHP paths for file_get_contents

This seems like a simple and general task, but we cannot get it to work:

We have two of us working on a project, and both of our machines are installed as local servers with a production environment.

At the beginning of our entire project, we have PHP. As below:

$feed = "/lib/php/backend/gateway.php?action=history";
$json = file_get_contents($feed, true);

The only way to make it work is to set it as the full URL, for example http://dev01.domain.com/lib/php/backend/gateway.php?action=history , or configure it as a local host this way

$feed = "http://localhost/lib/php/backend/gateway.php?action=history";
$json = file_get_contents($feed, true);

The latter, obviously, works on our local boxes and will presumably work in production, but is there a way to use relative paths to be a little cleaner?

+5
source share
2
$feed = 'http://' . $_SERVER['HTTP_HOST'] . '/lib/php/backend/gateway.php?action=history';

-

$feed = "/lib/php/backend/gateway.php?action=history";
$json = file_get_contents($feed, true);

, PHP . , PHP- , .

http://localhost/...., PHP URL-, HTTP- -, .

.

, gateway.php ? , HTTP- .

+10

/lib/php/backend/gateway.php?action=history /-

.

function gateway($action)
{
  // existing code
}
$json = gateway('history');

, HTTP-
( file_get_contents)

+2
source

All Articles