diff --git a/functions.php b/functions.php index b54d9e7931a8bcd1684b210833e65563526b4a9e..c063458b6b124a0006f65cdaa80dfeadbcd3088f 100644 --- a/functions.php +++ b/functions.php @@ -41,3 +41,15 @@ function getHostJson($librehostJsonUrl) { $response = json_decode($response, true); return $response; } + +function moveHostToBeginning(&$hosts, $query) { + $query = strtolower($query); + foreach ($hosts as $key => $host) { + if (strtolower($host['name']) === $query) { + $h = $host; + unset($hosts[$key]); + array_unshift($hosts, $h); + break; + } + } +} diff --git a/index.php b/index.php index 781ba4a2900ec41acc9b351f9c19e28626892091..4580aea3ad65b7c23e098683381a2db7b5ed7858 100644 --- a/index.php +++ b/index.php @@ -53,6 +53,13 @@ if ($recache) { echo "Cache is valid"; } +shuffle($hosts); + +if (isset($_GET['h'])) { + $query = $_GET['h']; + moveHostToBeginning($hosts, $query); +} + ?> @@ -70,7 +77,6 @@ if ($recache) {