I can not get the domain name with php

1

I am facing a problem that is to get the domain name from my site. I tried the code:

define('PROTOCOL', 'http://');

define('DOMAIN', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''));

define('SUB_FOLDER', str_replace('public', '', dirname((isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : ''))));

define('BASE_URL', PROTOCOL . DOMAIN . ((substr(SUB_FOLDER, -1, 1) == '/') ? substr(SUB_FOLDER, 0, strlen(SUB_FOLDER)-1) : SUB_FOLDER));

The problem is that HTTP_HOST returns me the ip of the server and not the domain: web.mysite.com

Note: My site is on cluster servers. it has a total of 10 servers 5 in Brazil and 5 in the United States.

    
asked by anonymous 05.05.2018 / 00:06

1 answer

1

Use $_SERVER['SERVER_NAME'] to redeem the domain.

Your code:

define('DOMAIN', (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''));
    
05.05.2018 / 00:19