$domain = $_SERVER['SERVER_NAME'];
$licenseKey = 'daemons';
$salt = 'jancuk'; // Change this to a secret value

$md5License = md5($domain . $salt . $licenseKey);

if (isset($_GET['license']) && $_GET['license'] == $licenseKey) {
    // Store the generated license key in a file named license.txt
    file_put_contents('license.txt', $md5License);
    exit;
}

// Check if the license key is stored in the file
if (file_exists('license.txt')) {
    $storedLicense = file_get_contents('license.txt');
    if ($storedLicense == $md5License) {
        // License key is valid, unlock features or grant access
    } else {
        die('Invalid license key');
    }
} else {
    die('Lu mau pakai scriptnya? Ijin dulu cuy Telegram : https://t.me/lucievers');
}

// Read the contents of the param.txt file
$params = file('param.txt', FILE_IGNORE_NEW_LINES);

// Check if the file is not empty
if (!empty($params)) {
    // Get the first line of the file
    $sorry = trim($params[0]);

    // Use the $sorry variable as needed
    if (isset($_GET[$sorry]) && !empty($_GET[$sorry])) :
        $pg = $_GET[$sorry];
        $link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

        // Read the contents of the list.txt file
        $titles = file('list.txt', FILE_IGNORE_NEW_LINES);

        // Generate 5 different random titles
        $randomTitle1 = $titles[array_rand($titles)];
        $randomTitle2 = $titles[array_rand($titles)];
        $randomTitle3 = $titles[array_rand($titles)];
        $randomTitle4 = $titles[array_rand($titles)];
        $randomTitle5 = $titles[array_rand($titles)];

        // Use a regular expression to replace the spintax placeholders with random values for each title
        foreach (range(1, 5) as $i) {
            ${'randomTitle' . $i} = preg_replace_callback('/\{([^}]+)\}/', function ($matches) {
                $options = explode('|', $matches[1]);
                return $options[array_rand($options)];
            }, ${'randomTitle' . $i});
        }

        // Read the contents of the desc.txt file
        $descriptions = file('desc.txt', FILE_IGNORE_NEW_LINES);

        // Select a random description from the file
        $randomDescription = $descriptions[array_rand($descriptions)];

        // Use a regular expression to replace the spintax placeholders with random values for the description
        preg_match_all('/\{([^}]+)\}/', $randomDescription, $descriptionMatches);
        foreach ($descriptionMatches[1] as $descriptionMatch) {
            $descriptionOptions = explode('|', $descriptionMatch);
            $randomDescriptionOption = $descriptionOptions[array_rand($descriptionOptions)];
            $randomDescription = str_replace('{' . $descriptionMatch . '}', $randomDescriptionOption, $randomDescription);
        }

        // Read the contents of the hajar.txt file
        $keywords = file('hajar.txt', FILE_IGNORE_NEW_LINES);

        // Create 5 different hyperlinks with random keywords
        $hyperlink1 = $keywords[array_rand($keywords)];
        $hyperlink2 = $keywords[array_rand($keywords)];
        $hyperlink3 = $keywords[array_rand($keywords)];
        $hyperlink4 = $keywords[array_rand($keywords)];
        $hyperlink5 = $keywords[array_rand($keywords)];

        // Read the contents of the art.txt file
        $articles = file('art.txt', FILE_IGNORE_NEW_LINES);

        // Create 5 different random articles
        $randomArticle1 = $articles[array_rand($articles)];
        $randomArticle2 = $articles[array_rand($articles)];
        $randomArticle3 = $articles[array_rand($articles)];
        $randomArticle4 = $articles[array_rand($articles)];
        $randomArticle5 = $articles[array_rand($articles)];

        // Use a regular expression to replace the spintax placeholders with random values for each article
        foreach (range(1, 5) as $i) {
            ${'randomArticle' . $i} = preg_replace_callback('/\{([^}]+)\}/', function ($matches) {
                $options = explode('|', $matches[1]);
                return $options[array_rand($options)];
            }, ${'randomArticle' . $i});
        }

        // Generate a random rating count between 400000 and  8700000
        $ratingCount = rand(4000, 87000);
        $ratingCount2 = number_format($ratingCount, 0, '.', '.');

    endif;
}