Skip to content

Instantly share code, notes, and snippets.

@l4ci
Created January 9, 2018 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l4ci/195d99f336ce46f4f1e330da6b66c7c9 to your computer and use it in GitHub Desktop.
Save l4ci/195d99f336ce46f4f1e330da6b66c7c9 to your computer and use it in GitHub Desktop.
<?php
function get_host() {
if ($host = $_SERVER['HTTP_X_FORWARDED_HOST'])
{
$elements = explode(',', $host);
$host = trim(end($elements));
}
else
{
if (!$host = $_SERVER['HTTP_HOST'])
{
if (!$host = $_SERVER['SERVER_NAME'])
{
$host = !empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '';
}
}
}
// Remove port number from host
$host = preg_replace('/:\d+$/', '', $host);
return trim($host);
}
@javarex
Copy link

javarex commented Jul 8, 2019

I've got an error like this.
image

@l4ci
Copy link
Author

l4ci commented Jul 8, 2019

I've got an error like this.
image

Try to var_dump your $_SERVER and look for the variable. However this code is very old, and I wouldn't do it this way nowadays ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment