jcubic
jcubic

Reputation: 66620

How to get host name from php on shared hosting?

On shared hosting (on subdomain notes.jcubic.pl) I've try to use:

$host = gethostname();

but got n114.domenomania.pl (real server name) is there a way to get notes.jcubic.pl subdomain?

Upvotes: 2

Views: 1730

Answers (3)

Cassey27
Cassey27

Reputation: 5

you can use this also for connecting in localhost server $db_host = "localhost";

Upvotes: -1

user7810601
user7810601

Reputation:

For PHP >= 5.3.0 use this:

$hostname = gethostname();

For PHP < 5.3.0 but >= 4.2.0 use this:

$hostname = php_uname('n');

For PHP < 4.2.0 use this:

$hostname = getenv('HOSTNAME'); if(!$hostname) $hostname = trim(hostname); if(!$hostname) $hostname = exec('echo $HOSTNAME'); if(!$hostname) $hostname = preg_replace('#^\w+\s+(\w+).*$#', '$1', exec('uname -a'));

Upvotes: 0

Simone Cabrino
Simone Cabrino

Reputation: 931

Are you looking lot the $_SERVER['HTTP_HOST']?

Upvotes: 2

Related Questions