Conditions | 4 |
Paths | 4 |
Total Lines | 34 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | static function exec($url, $fields) { |
||
|
|||
12 | |||
13 | |||
14 | $fields_string = ""; |
||
15 | //url-ify the data for the POST |
||
16 | if(count($fields)>0) { |
||
17 | foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } |
||
18 | rtrim($fields_string, '&'); |
||
19 | } |
||
20 | |||
21 | //echo $fields_string; |
||
22 | //open connection |
||
23 | $ch = curl_init(); |
||
24 | |||
25 | //set the url, number of POST vars, POST data |
||
26 | curl_setopt($ch,CURLOPT_URL, $url); |
||
27 | curl_setopt($ch,CURLOPT_POST, count($fields)); |
||
28 | curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); |
||
29 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
30 | curl_setopt ($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie"); |
||
31 | curl_setopt($ch, CURLOPT_COOKIEJAR, "TelegramBot/JarvisPHPSession.cookie"); |
||
32 | |||
33 | //execute post |
||
34 | $result = @curl_exec($ch); |
||
35 | |||
36 | $http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||
37 | |||
38 | //close connection |
||
39 | curl_close($ch); |
||
40 | |||
41 | |||
42 | |||
43 | return ($http_response_code==200) ? json_decode($result) : false; |
||
44 | } |
||
45 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.