Skip to content

Commit c41ef17

Browse files
committed
feat: switch api call to curl
1 parent 4ac870c commit c41ef17

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Request.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,14 @@ public static function getLocationFromIp(string $ip): array
768768
];
769769

770770
try {
771-
$res = file_get_contents("http://ip-api.com/json/{$response['ip']}?fields=status,continent,continentCode,country,countryCode,region,regionName,city,zip,lat,lon,timezone,currency,query");
771+
$ch = curl_init();
772+
curl_setopt($ch, CURLOPT_URL, "http://ip-api.com/json/{$ip}?fields=status,continent,continentCode,country,countryCode,region,regionName,city,zip,lat,lon,timezone,currency,query");
773+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
774+
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
775+
776+
$res = curl_exec($ch);
777+
curl_close($ch);
778+
772779
$data = json_decode($res ?? '{}', true);
773780

774781
if (($data['status'] ?? false) === 'success') {

0 commit comments

Comments
 (0)