$init = $_POST['external_url'] ?? null;
$preparedLink = prepareExternalLink($init);
$sth = db_query("SELECT external_url, created_short_id FROM result WHERE external_url='" . $preparedLink . "'")->fetch();
if ($sth) {
$_COOKIE['unique_url'] = false;
} elseif (isset($_COOKIE['url_empty'])) {
$_COOKIE['unique_url'] = false;
} elseif (isset($_COOKIE['url_incorrect'])) {
$_COOKIE['unique_url'] = false;
} else {
$_COOKIE['unique_url'] = true;
}
$short_url = "{$_SERVER['HTTP_HOST']}/r_{$sth['created_short_id']}";
if ($sth !== false) {
$sth = array_merge($sth, ['short_link' => $short_url]);
$sth = changeKeyExistArray($sth,
['external_url', 'created_short_id', 'short_link', 0],
['External_url', 'ID_short_url', 'Result_url', 'Unique_url']);
}