-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.php
More file actions
43 lines (28 loc) · 941 Bytes
/
date.php
File metadata and controls
43 lines (28 loc) · 941 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
38
39
40
41
42
43
<?php
$token = array('token' => 'Zsh0UXjDre');
$json_token = json_encode($token);
function postData($url, $data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
return $result;
}
//Get date and seconds
$result = postData('http://challenge.code2040.org/api/time', $json_token);
$array = json_decode($result,TRUE);
$date = $array['result']['datestamp'];
$seconds = $array['result']['interval'];
//Convert to unix time
date_default_timezone_set('America/Los_Angeles');
$unixtime = strtotime($date);
//Add interval of seconds
$newdate = $unixtime + $seconds;
$data = date('c', $newdate);
$isodate = array('token' => 'Zsh0UXjDre' ,'datestamp' => $data);
$json_date = json_encode($isodate);
//POST data
$ans = postData('http://challenge.code2040.org/api/validatetime', $json_date);
echo $ans;
?>