Fingolricks
Fingolricks

Reputation: 1212

in php, How to detect the server where you work

I am currently working locally on a project that, once I finish my tasks, I have to upload the changes to a server (which is in the cloud).

The problem is that there are certain addresses that I pointed directly and when uploaded to the server, I have need to change then manually, for example:

Locally http://localhost/project/user/test1

to

In the cloud http://ourserver/projectXYZ/user/test1

Is there any way in php, to know the address of the server where you are and, with this, put these dynamic addresses?

Upvotes: 0

Views: 70

Answers (1)

lafor
lafor

Reputation: 12776

It's best to use URIs that are relative to the document root, without the host part, e.g. /projectXYZ/user/test1. That said, sometimes you need to know the hostname (e.g. if you ever do a 30x redirect, RFC 2616 requires the Location: header to absolute URI). In cases like this, your best bet is to check $_SERVER['HTTP_HOST'], which has the "contents of the Host: header from the current request, if there is one", to quote PHP manual. I wouldn't worry too much about the "if there is one" part; since Host: header is mandatory in HTTP, it missing would be an extremely rare edge case.

Upvotes: 1

Related Questions