-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.php
More file actions
54 lines (33 loc) · 933 Bytes
/
reverse.php
File metadata and controls
54 lines (33 loc) · 933 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
44
45
46
47
48
49
50
51
52
53
54
<?php
$token = array('token' => 'Zsh0UXjDre');
$json_token = json_encode($token);
// get string
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;
}
$result = postData('http://challenge.code2040.org/api/getstring', $json_token);
if(!$result) {
echo "There was a problem getting the string";
exit();
}
// convert JSON object to string
$obj = json_decode($result);
foreach ($obj as $key => $val) {
$string = $val;
}
// reverse string
$reverse = strrev($string);
//set reversed string and token in array
$answer = array(
'token' => 'Zsh0UXjDre',
'string' => $reverse);
$json_answer = json_encode($answer);
//POST answer
$result = postData('http://challenge.code2040.org/api/validatestring', $json_answer);
echo $result;
?>