// Использовать в index.html, перед закрывающимся тегом /head
// Использовать в api.php, после открывающего тега php
function isDuplicateLead($phone)
{
$file = 'leads.txt';
if (!file_exists($file)) {
file_put_contents($file, '');
}
$leads = file_get_contents($file);
$escapedPhone = preg_quote($phone, '/');
$phonePattern = '/' . $escapedPhone . "\n/";
if (preg_match($phonePattern, $leads)) {
return true;
} else {
file_put_contents($file, $phone . "\n", FILE_APPEND);
return false;
}
}
function cleanPhoneNumber($phoneNumber)
{
return preg_replace('/[^0-9]/', '', $phoneNumber);
}
$cleanedPhone = cleanPhoneNumber($_POST['phone']);
if (isDuplicateLead($cleanedPhone)) {
header('Location: error.php');
exit;
}