-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovieApi.php
51 lines (43 loc) · 1.65 KB
/
movieApi.php
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
42
43
44
45
46
47
48
49
50
51
<?php
// todo
// $servername = "localhost";
// $username = "root";
// $password = "";
// $db="movie";
// $conn = mysqli_connect($servername, $username, $password,$db);
// Fetching Values From URL
if ($_POST['method'] === "search") {
$search1 = $_POST['search'];
$key = "2d3933b370ff193110922c3b68cd842b";
$json = file_get_contents("https://api.themoviedb.org/3/search/movie?api_key=$key&query=$search1&page=1");
// todo
// $ip = $_SERVER['REMOTE_ADDR'];
// $sql = "INSERT INTO `crud`( `searchTerm`, `dateTime`, `ipAddress`)
// VALUES ('$search1','NOW()','$ip')";
// if (mysqli_query($conn, $sql)) {
// echo json_encode(array("statusCode"=>200));
// }
// else {
// echo json_encode(array("statusCode"=>201));
// }
// mysqli_close($conn);
echo $json;
} else if ($_POST['method'] === "details") {
$search1 = $_POST['search'];
$search1 = str_replace(' ', '+', $search1);
$key = "2d3933b370ff193110922c3b68cd842b";
$json = file_get_contents("https://api.themoviedb.org/3/search/movie?api_key=$key&query=$search1&page=1");
// todo
// $ip = $_SERVER['REMOTE_ADDR'];
// $sql = "INSERT INTO `crud`( `searchTerm`, `dateTime`, `ipAddress`)
// VALUES ('$search1','NOW()','$ip')";
// if (mysqli_query($conn, $sql)) {
// echo json_encode(array("statusCode"=>200));
// }
// else {
// echo json_encode(array("statusCode"=>201));
// }
// mysqli_close($conn);
echo $json;
}
?>