-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefix.php
More file actions
54 lines (35 loc) · 1.06 KB
/
prefix.php
File metadata and controls
54 lines (35 loc) · 1.06 KB
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);
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 info and transfer to array that I can work with
$result = postData('http://challenge.code2040.org/api/prefix', $json_token);
$prefix = json_decode($result, TRUE);
$string = $prefix['result']['prefix'];
$prefixarray = array();
foreach ($prefix['result']['array'] as $key => $val){
$prefixarray[] = $val;
}
$nonprefix = array();
$found = null;
for($i=0;$i<count($prefixarray);$i++) {
// check to see if it finds prefix string in array
$found = strpos($prefixarray[$i], $string);
if ($found === FALSE){
$nonprefix[] = $prefixarray[$i];
}
}
//POST data
$info = array('token' => 'Zsh0UXjDre',
'array' => $nonprefix);
$json_info = json_encode($info);
$ans = postData('http://challenge.code2040.org/api/validateprefix', $json_info);
echo $ans;
?>