-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcURL-polyfill.php
More file actions
118 lines (98 loc) · 1.99 KB
/
cURL-polyfill.php
File metadata and controls
118 lines (98 loc) · 1.99 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
if(!function_exists("curl_init"))
{
function curl_init()
{
return new Curl();
}
function curl_setopt(&$ch, $option, $value)
{
$ch->setopt($option, $value);
}
function curl_getinfo(&$ch, $opt)
{
return $ch->getinfo($opt);
}
function curl_exec(&$ch)
{
return $ch->execute();
}
function curl_close(&$ch)
{
$ch->close();
}
class Curl
{
function setopt($option, $value)
{
$this->$option = $value;
}
function getinfo($opt)
{
return $this->{$opt};
}
function close()
{
if($this->fp)
{
fclose($this->fp);
unset($this->fp);
}
}
function execute()
{
if(gettype($this->{CURLOPT_POSTFIELDS}) == 'array')
{
$data = http_build_query($this->{CURLOPT_POSTFIELDS});
}
else
{
$data = $this->{CURLOPT_POSTFIELDS};
}
$params = array('http' =>
array(
'content' => $data
)
);
$method = "GET";
$method = $this->{CURLOPT_POST} ? "POST" : $method;
$method = $this->{CURLOPT_CUSTOMREQUEST} ? $this->{CURLOPT_CUSTOMREQUEST} : $method;
if($method != "GET")
{
$params['http']['method'] = $method;
}
$params['http']['header'] = implode("\r\n", $this->{CURLOPT_HTTPHEADER});
$ctx = stream_context_create($params);
$fp = @fopen($this->{CURLOPT_URL}, 'rb', false, $ctx);
$this->fb = $fp;
try
{
if (!$fp) {
throw new Exception("Problem with {$this->{CURLOPT_URL}}, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
$meta = @stream_get_meta_data($fp);
$status = explode(' ',$meta['wrapper_data'][0]);
$this->{CURLINFO_HTTP_CODE} = $status[1];
if($this->{CURLOPT_RETURNTRANSFER})
{
return $response;
}
else
{
echo $response;
}
}
catch (Exception $e)
{
pre($params);
$debug = debug_backtrace();
pre($debug);
pre($e->getMessage());
}
return;
}
}
}