I can’t get the domain name with php

Asked

Viewed 56 times

1

I am facing a problem that is to get the domain name of my website. 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 server ip and not the domain: web.meusite.com.br

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

1 answer

1

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

Your code:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.