-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogsSender.php
More file actions
41 lines (34 loc) · 1.05 KB
/
LogsSender.php
File metadata and controls
41 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace Cleantalk\PHPAntiCrawler;
final class LogsSender
{
/**
* @param array<int, array<int, mixed>> $data
*/
public static function sendDataQuery(string $apiKey, array $data): bool
{
$postFields = [
'timestamp' => time(),
'rows' => count($data),
'data' => json_encode($data, JSON_UNESCAPED_SLASHES),
];
$url = 'https://api.cleantalk.org/?method_name=sfw_logs&auth_key=' . urlencode($apiKey);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($postFields),
]);
$response = curl_exec($ch);
if ($response === false) {
curl_close($ch);
return false;
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
return ($status === 200);
}
}