-
Notifications
You must be signed in to change notification settings - Fork 15
/
demo.php
78 lines (59 loc) · 1.75 KB
/
demo.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
77
78
<!DOCTYPE html>
<html>
<head>
<title>Poslaju API Demo</title>
</head>
<body>
<form action="./demo.php" method="get">
Tracking No:
<input type="text" name="trackingNo" placeholder="Tracking no, ex: ER126406955MY" value="ER126406955MY">
<button type="submit">Track</button>
</form>
<?php
if(isset($_GET['trackingNo']))
{
$trackingNo = $_GET['trackingNo']; # your tracking number
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://".$_SERVER['HTTP_HOST']."/api.php?trackingNo=".$trackingNo; # the full URL to the API
$getdata = file_get_contents($url); # use files_get_contents() to fetch the data, but you can also use cURL, or javascript/jquery json
$parsed = json_decode($getdata,true); # decode the json into array. set true to return array instead of object
$httpcode = $parsed["http_code"];
$message = $parsed["message"];
echo "<br><b>Status: ".$message . "</b><br>";
if($message == "Record Found" && $httpcode == 200)
{
?>
<table border=1>
<tr>
<th>Date/Time</th>
<th>Process</th>
<th>Event</th>
</tr>
<?php
# iterate through the array
for($i=0;$i<count($parsed['data']);$i++)
{
# access each items in the JSON
echo "
<tr>
<td>".$parsed['data'][$i]['date_time']."</td>
<td>".$parsed['data'][$i]['process']."</td>
<td>".$parsed['data'][$i]['event']."</td>
</tr>
";
}
?>
</table>
<br><br>
<b>JSON output:</b><br>
<pre style="height:500px;width:700px;border:1px solid #ccc;overflow:auto;">
<?php
$json_pretty = json_encode(json_decode($getdata), JSON_PRETTY_PRINT);
echo $json_pretty;
?>
</pre>
<?php
}
}
?>
</body>
</html>