-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.php
More file actions
35 lines (27 loc) · 997 Bytes
/
load.php
File metadata and controls
35 lines (27 loc) · 997 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
<?php
function getSearchResults($query, $start = 1)
{
$apiKey = 'xxxx'; // put your api...
$cx = 'xxxx'; // put your cs id of your programmable search engine..
$url = "https://www.googleapis.com/customsearch/v1?key=$apiKey&cx=$cx&q=" . urlencode($query) . "&start=" . urlencode($start);
// Make the request and get the response
$response = file_get_contents($url);
// Check if the response is not false
if ($response === FALSE) {
echo json_encode(['error' => 'Request failed']);
exit();
}
// Decode the JSON response into an associative array
$data = json_decode($response, true);
// Return the decoded data
return $data;
}
$query = isset($_GET['q']) ? htmlspecialchars($_GET['q']) : "";
$start = isset($_GET['start']) ? (int)$_GET['start'] : 1;
if ($query) {
$searchResults = getSearchResults($query, $start);
echo json_encode($searchResults);
} else {
echo json_encode(['error' => 'No query provided']);
}
?>