-
Notifications
You must be signed in to change notification settings - Fork 1
/
NetPHP.php
163 lines (163 loc) · 4.8 KB
/
NetPHP.php
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
*
* @Name : NetPHP.php
* @Version : 1.1
* @Programmer : Max
* @Date : 2019-05-26, 2019-08-17
* @Released under : https://github.com/BaseMax/NetPHP/blob/master/LICENSE
* @Repository : https://github.com/BaseMax/NetPHP
*
**/
$debug=false;
// $debug=true;
$debug_details=true;
$debug_details=false;
function useragent() {
return "Mozilla/5.0 (Windows NT 6.1; r…) Gecko/20100101 Firefox/60.0";
return "Mozilla/5.0(Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36(KHTML,like Gecko) curlrome/68.0.3440.106 Mobile Safari/537.36";
}
function get_headers_from_curl_response($headerContent) {
$headers = array();
$arrRequests = explode("\r\n\r\n",$headerContent);
for($index = 0; $index < count($arrRequests) -1; $index++) {
foreach(explode("\r\n",$arrRequests[$index]) as $i => $line) {
if($i === 0)
$headers[$index]['http_code'] = $line;
else {
list($key,$value) = explode(': ',$line);
$headers[$index][$key] = $value;
}
}
}
return $headers;
}
function post($url,$values=[],$headers=[],$reffer="",$auto_redirect=true) {
global $debug,$debug_details;
if($debug) {
print "@Request[POST]----------------------------------------------\n";
print "----------@link ".$url."\n";
if($debug_details) {
if($reffer!="") {
print "----------@Reffer\n";
print $reffer;
print "\n";
}
if(count($values)!=0) {
print "----------@Values\n";
print_r($values);
}
if(count($headers)!=0) {
print "----------@Headers\n";
print_r($headers);
}
}
}
$curl = curl_init($url);
if(is_array($headers)) {
curl_setopt($curl,CURLOPT_HTTPHEADER,$headers);
}
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,true);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,$auto_redirect);
curl_setopt($curl,CURLOPT_HEADER,true);
curl_setopt($curl,CURLOPT_VERBOSE,false);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$values);
curl_setopt($curl,CURLOPT_USERAGENT,useragent());
curl_setopt($curl,CURLOPT_COOKIEJAR,"_cookies.txt");
curl_setopt($curl,CURLOPT_COOKIEFILE,"_cookies.txt");
if($reffer != "")
curl_setopt($curl,CURLOPT_REFERER,$curl);
$response = curl_exec($curl);
$header_size = curl_getinfo($curl,CURLINFO_HEADER_SIZE);
$header = substr($response,0,$header_size);
$body = substr($response,$header_size);
$httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
if($debug && $debug_details) {
print "----------@Response Headers\n";
print_r($header);
print "----------@Response Body\n";
print_r($body);
print "\n";
}
if($httpCode == 404) {
return false;
}
return [$body,$header];
}
function get($url,$headers=[],$reffer="",$auto_redirect=true)
{
global $debug,$debug_details;
if($debug) {
print "@Request[GET]----------------------------------------------\n";
print "----------@link ".$url."\n";
if($debug_details) {
if($reffer!="") {
print "----------@Reffer\n";
print $reffer;
print "\n";
}
if(count($headers)!=0) {
print "----------@Headers\n";
print_r($headers);
}
}
}
$curl = curl_init($url);
if(is_array($headers)) {
curl_setopt($curl,CURLOPT_HTTPHEADER,$headers);
}
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,true);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,$auto_redirect);
curl_setopt($curl,CURLOPT_HEADER,true);
curl_setopt($curl,CURLOPT_VERBOSE,false);
curl_setopt($curl,CURLOPT_POST,false);
curl_setopt($curl,CURLOPT_USERAGENT,useragent());
curl_setopt($curl,CURLOPT_COOKIEJAR,"_cookies.txt");
curl_setopt($curl,CURLOPT_COOKIEFILE,"_cookies.txt");
if($reffer != "")
curl_setopt($curl,CURLOPT_REFERER,$curl);
$response = curl_exec($curl);
$header_size = curl_getinfo($curl,CURLINFO_HEADER_SIZE);
$header = substr($response,0,$header_size);
$body = substr($response,$header_size);
$httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
curl_close($curl);
if($debug && $debug_details) {
print "----------@Response Headers\n";
print_r($header);
print "----------@Response Body\n";
print_r($body);
print "\n";
}
if($httpCode == 404) {
return false;
}
return [$body,$header];
}
////////////////////////////////////////////////////////
/*
function random() {
// like Math.random() in JS
return(float)rand()/(float)getrandmax();
}
function store_token($response) {
preg_match_all("/name=\"\_token\" value=\"(?<token>[^\"]+)\"/i",$response,$tokens);
if(!isset($tokens["token"][0])) {
exit("No Token value in login page!\n");
}
return $tokens["token"][0];
}
function get_parse($content,$name) {
//name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value=""
preg_match('/name="'.$name.'" id="'.$name.'" value="(?<value>[^\"]+)"/i',$content,$values);
// print_r($values);
$value=$values["value"];
$value=str_replace("-","+",$value);
$value=str_replace("_","/",$value);
return $value;
}
*/