-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapi.php
76 lines (65 loc) · 2.12 KB
/
api.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
header('Content-Type: application/json');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $_REQUEST['url'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => array(
"Accept-Encoding: gzip, deflate",
"Connection: keep-alive",
"Host: sepatucompass.com",
"accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-language: en-US,en;q=0.9",
"cache-control: max-age=0,no-cache",
"if-modified-since: Wed, 09 Oct 2019 09:30:00 GMT",
"sec-fetch-mode: navigate",
"sec-fetch-site: none",
"sec-fetch-user: ?1",
"upgrade-insecure-requests: 1",
"user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
) ,
));
$response = curl_exec($curl);
$err = curl_error($curl);
preg_match_all('~("ProductSelect-(.*?)-option-0">)~', $response, $id);
$id = $id[2][0];
$ex = explode('<select name="id" id="ProductSelect-' . $id . '" class="product-single__variants no-js">', $response);
$ex = explode('</select>', $ex[1]);
$ex1 = explode('<option disabled="disabled">', $ex[0]);
for ($i = 1;$i < count($ex1);$i++)
{
$exi = explode("</option>", $ex1[$i]);
//$stat[] = $stat;
//$hasil['available'] = $stat;
$details[] = trim($exi[0]);
}
for ($i = 0;$i < count($details);$i++)
{
$status = preg_match("/Sold Out/", $details[$i]);
if ($status == true)
{
$stat = "no";
}
else
{
$stat = "yes";
}
$available[] = $stat;
}
for ($i = 0;$i < count($details);$i++)
{
$res[] = ['available' => $available[$i], 'details' => $details[$i], ];
}
$result['link'] = @$_REQUEST['url'];
$result['id'] = $id;
$result['stock'] = $res;
echo json_encode($result, JSON_PRETTY_PRINT);
?>