Здравствуйте как мне сделать проверку на наличие домена в базе данных
есть движок gamecms он отправляет все нужные данные
вот код:
<?PHP
require($_SERVER['DOCUMENT_ROOT'] . '/inc/start.php');
if(empty($_POST['phpaction'])) {
exit(json_encode(['status' => '2']));
}
if($_SESSION['token'] != $_POST['token']) {
exit(json_encode(['status' => '2']));
}
if(!is_admin()) {
echo 'Ошибка: [Доступно только администратору]';
exit(json_encode(['status' => '2']));
}
if(isset($_POST['setup_key_market'])) {
$key = checkJs($_POST['key'], null);
if(empty($key)) {
exit(json_encode(['status' => '2', 'message' => 'Введите ключ.']));
}
ignore_user_abort(1);
set_time_limit(0);
$wa = new market($pdo);
if($_POST['is_template'] == '1') {
$result = json_decode(gzdecode($wa->teps("&product=gamecms&resource={$_SERVER['SERVER_NAME']}&code={$_POST['key']}")),true);
if($result['status'] == 2) { exit(json_encode(['status' => '2', 'message' => $result['message']])); }
$link = $result['file'];
$arr = explode("/", $link);
$zip_file = $arr[count($arr) - 1];
$template_name = $result['name'];
$path = $_SERVER['DOCUMENT_ROOT'] . '/templates/';
mkdir($path, 0777);
$update_file = $path.$zip_file;
$cInit = curl_init($link);
$fOpen = fopen($update_file, "wb");
curl_setopt($cInit, CURLOPT_FILE, $fOpen);
curl_setopt($cInit, CURLOPT_HEADER, 0);
curl_exec($cInit);
curl_close($cInit);
fclose($fOpen);
$archive = new PclZip($update_file);
$result = $archive->extract(PCLZIP_OPT_PATH, $path);
unlink($update_file);
exit(json_encode([
'status' => '1',
'message' => 'Шаблон "'.$template_name.'" успешно установлен!'
]));
}
$result = $wa->curl_get_process([
'website' => "https://tpl-market.ru/api?type=downloads",
'data' => "&product=gamecms&resource={$_SERVER['SERVER_NAME']}&code={$_POST['key']}"
]);
$result = json_decode(gzdecode($result), true);
if($result['status'] == 2) {
exit(json_encode(['status' => '2', 'message' => $result['message']]));
}
$link = $result['file'];
$arr = explode("/", $link);
$zip_file = $arr[count($arr) - 1];
$module_name = $result['name'];
$STH = $pdo->prepare("SELECT id FROM modules WHERE name=:name LIMIT 1");
$STH->setFetchMode(PDO::FETCH_OBJ);
$STH->execute([':name' => $module_name]);
$row = $STH->fetch();
if(isset($row->id)) {
exit(json_encode(['status' => '2', 'message' => 'Данный модуль уже установлен']));
}
$path = $_SERVER['DOCUMENT_ROOT'] . '/modules_extra/';
if(!file_exists($path)) {
mkdir($path, 0777);
}
$update_file = $path.$zip_file;
$cInit = curl_init($link);
$fOpen = fopen($update_file, "wb");
curl_setopt($cInit, CURLOPT_FILE, $fOpen);
curl_setopt($cInit, CURLOPT_HEADER, 0);
curl_exec($cInit);
curl_close($cInit);
fclose($fOpen);
$archive = new PclZip($update_file);
$result = $archive->extract(PCLZIP_OPT_PATH, $path);
unlink($update_file);
$tpls_path = $path . $module_name . "/settings/tpls.txt";
$pages_path = $path . $module_name . "/settings/pages.txt";
$base_path = $path . $module_name . "/settings/base.sql";
$info_path = $path . $module_name . "/settings/info.txt";
$files_path = $path . $module_name . "/settings/files.txt";
if(file_exists($tpls_path)) {
$tpls = file_get_contents(trim($tpls_path));
unlink($tpls_path);
} else {
$tpls = 'none';
}
if(file_exists($pages_path)) {
$pages = file_get_contents(trim($pages_path));
eval('$pages = ' . $pages);
unlink($pages_path);
} else {
$pages = 'none';
}
if(file_exists($base_path)) {
$pdo->exec(trim(file_get_contents($base_path)));
unlink($base_path);
}
if(file_exists($info_path)) {
$info = file_get_contents(trim($info_path));
unlink($info_path);
}
else {
$info = "";
}
if(file_exists($files_path)) {
$files = file_get_contents(trim($files_path));
unlink($files_path);
} else {
$files = '';
}
$STH = $pdo->prepare(
"INSERT INTO modules (name,tpls,info,files,client_key) values (:name, :tpls, :info, :files, :client_key)"
);
$STH->execute(
[':name' => $module_name, ':tpls' => $tpls, ':info' => $info, ':files' => $files, ':client_key' => $key]
);
if(is_array($pages)) {
$module_id = get_ai($pdo, "modules");
$module_id--;
for($i = 0; $i < count($pages); $i++) {
$STH = $pdo->prepare(
"INSERT INTO pages (file,url,name,title,description,keywords,kind,image,robots,privacy,type,active,module,page,class) values (:file, :url, :name, :title, :description, :keywords, :kind, :image, :robots, :privacy, :type, :active, :module, :page, :class)"
);
$STH->execute(
[
':file' => $pages[$i]['file'],
':url' => $pages[$i]['url'],
':name' => $pages[$i]['name'],
':title' => $pages[$i]['title'],
':description' => $pages[$i]['description'],
':keywords' => $pages[$i]['keywords'],
':kind' => $pages[$i]['kind'],
':image' => $pages[$i]['image'],
':robots' => $pages[$i]['robots'],
':privacy' => $pages[$i]['privacy'],
':type' => $pages[$i]['type'],
':active' => $pages[$i]['active'],
':module' => $module_id,
':page' => '0',
':class' => '0'
]
);
}
}
exit(json_encode(['status' => '1', 'message' => 'Модуль "'.$module_name.'" - успешно установлен (обновите стр.)']));
}
этот код проверяет наличие домена в базе данных на сайте где я получаю ключь
вот код с сайта где я получаю код
case "downloads": {
switch($_POST['product']) {
/* GameCMS */
case "gamecms": {
$q = $sql->query("SELECT * FROM `product__links` WHERE `code`='{$_POST['code']}'");
$r = $sql->arr($q);
if($r['timeleft'] + 600 < time()) {
exit(gzencode(json_encode([
'status' => '2',
'message' => 'Срок действия ключа закончился!'
])));
}
$q2 = $sql->query("SELECT * FROM `store__product` WHERE `id`='{$r['product_id']}'");
$r2 = $sql->arr($q2);
if($r2['binding']) {
$fqr = $sql->fqr("SELECT * FROM `product__binding` WHERE `id`='{$r['binding_id']}'");
/* Привязка товара */
if(empty($fqr['first_ip']) || $fqr['first_ip'] == 'none') {
$sql->query("UPDATE `product__binding` SET `first_ip`='{$_SERVER['REMOTE_ADDR']}' WHERE `id`='{$r['binding_id']}'");
}
else if($_SERVER['REMOTE_ADDR'] != $fqr['first_ip']) {
$bT = time() + 2678400;
$sql->query("UPDATE `product__binding` SET `block_ip`='{$_SERVER['REMOTE_ADDR']}', `block_date`='{$bT}',`reason`='Передача ключа.' WHERE `id`='{$r['binding_id']}'");
exit(gzencode(json_encode([
'status' => '2',
'message' => "Ваш ключ заблокирован!"
])));
}
if(time() < $fqr['block_date']) {
exit(gzencode(json_encode([
'status' => '2',
'message' => ("Ваш ключ заблокирован! Ждите " . floor(($fqr['block_date'] - time()) / 60) . " мин.")
])));
}
}
exit(gzencode(json_encode([
'status' => '1',
'name' => $r2['code_name'],
'file' => "https://{$_SERVER['SERVER_NAME']}/{$r2['file']}"
])));
break;
}
/* GameCMS */
}
exit("ok");
break;
}
вот это ссылка на апи
$result = $wa->curl_get_process([
'website' => "https://tpl-market.ru/api?type=downloads",
'data' => "&product=gamecms&resource={$_SERVER['SERVER_NAME']}&code={$_POST['key']}"
]);