KUJUNTI.ID MINISH3LL
Path : /var/www/html/phkaymedia/public/page/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/phkaymedia/public/page/get-sitemap.php


<?php
// Mulai output buffering untuk mencegah output yang tidak sengaja sebelum XML
ob_start();
error_reporting(0); // Matikan semua laporan kesalahan
ini_set('display_errors', 0); // Jangan tampilkan kesalahan ke output

// Fungsi untuk membersihkan karakter non-UTF-8
function clean_utf8($text) {
    return preg_replace('/[^\x00-\x7F]+/', '', $text); // Hapus karakter non-UTF-8
}

function getFileRowCount($filename) {
    $file = fopen($filename, "r");
    $rowCount = 0;

    while (!feof($file)) {
        fgets($file);
        $rowCount++;
    }

    fclose($file);

    return $rowCount;
}

$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 = rtrim($scheme . "://" . $host . dirname($path), '/') . '/'; // Menghilangkan duplikat '/'

    $judulFile = "list.txt";
    $jumlahBaris = getFileRowCount($judulFile);
    $sitemapFile = fopen("sitemap.xml", "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);

    $fileLines = file($judulFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach ($fileLines as $judul) {
        $judul = clean_utf8($judul); // Bersihkan judul
        $directory = strtolower(trim($judul));
        $directory = str_replace(' ', '-', $directory); // Ganti spasi dengan tanda hubung
        $sitemapLink = $baseUrl . $directory . '/'; // Gunakan baseUrl yang sesuai

        fwrite($sitemapFile, '  <url>' . PHP_EOL);
        fwrite($sitemapFile, '    <loc>' . htmlspecialchars($sitemapLink, ENT_QUOTES, 'UTF-8') . '</loc>' . PHP_EOL);
        fwrite($sitemapFile, '  </url>' . PHP_EOL);
    }

    fwrite($sitemapFile, '</urlset>' . PHP_EOL);
    fclose($sitemapFile);

    echo "SITEMAP DONE CREATE!";
} else {
    echo "URL saat ini tidak didefinisikan.";
}

// Akhiri output buffering dan kirim output
ob_end_flush();
?>

© KUJUNTI.ID