-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.php
More file actions
37 lines (31 loc) · 977 Bytes
/
proxy.php
File metadata and controls
37 lines (31 loc) · 977 Bytes
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
<?php
// Allow cross-origin requests from any domain
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
// Handle OPTIONS request (CORS preflight)
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200); // Preflight request successful
exit();
}
// WURFL API URL
$url = "https://wurfl.io/api/v1/json/device";
// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Execute request
$response = curl_exec($ch);
// Check if the cURL request was successful
if ($response === false) {
// cURL error handling
echo "cURL Error: " . curl_error($ch);
} else {
// Set content type to JSON and output the response
header('Content-Type: application/json');
echo $response;
}
// Close cURL session
curl_close($ch);
?>