File: php_curl.tpl

package info (click to toggle)
weevely 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,336 kB
  • sloc: python: 7,732; php: 1,035; sh: 53; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (4)
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
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "${url}");

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "${ request if not data else 'POST' }");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, ${ connect_timeout });
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

% if header or cookie or user_agent or data:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
% endif
% for h in header:
%   if not (data and (h.title().startswith('Content-Length: '))) and not (user_agent and h.title().startswith('User-Agent: ')):
        "${h}",
%   endif
% endfor
% if cookie:
          "Cookie: ${ cookie }",
% endif
% if user_agent:
          "User-Agent: ${ user_agent }",
% endif
% if header or cookie or user_agent or data:
  ));
% endif

% if data:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "${ ''.join(data) }");
% endif

curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
print($response);