Update webpagetool.php
This commit is contained in:
parent
a2f583721b
commit
244e9eaf16
|
@ -6,6 +6,39 @@
|
||||||
* @brief WebPageTool helper
|
* @brief WebPageTool helper
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if(!function_exists("get_web_legacy")) {
|
||||||
|
function get_web_legacy($url) {
|
||||||
|
return (ini_get("allow_url_fopen") ? file_get_contents($url) : false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!function_exists("get_web_cmd")) {
|
||||||
|
function get_web_cmd($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45) {
|
||||||
|
$output = "";
|
||||||
|
$cmd_fin = "";
|
||||||
|
$cmd = "";
|
||||||
|
|
||||||
|
if($method == "get") {
|
||||||
|
$cmd = "curl -A \"%s\" -k %s";
|
||||||
|
$cmd_fin = sprintf($cmd, $ua, $url);
|
||||||
|
$output = shell_exec($cmd_fin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($method == "post") {
|
||||||
|
$cmd = "curl -X POST -A \"%s\" -k %s %s";
|
||||||
|
$params_cmd = "";
|
||||||
|
foreach($data as $k=>$v) {
|
||||||
|
$v = addslashes($v);
|
||||||
|
$params_cmd .= "-d '{$k}={$v}' ";
|
||||||
|
}
|
||||||
|
$cmd_fin = sprintf($cmd, $ua, $url, $params_cmd);
|
||||||
|
$output = shell_exec($cmd_fin);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!function_exists("get_web_page")) {
|
if(!function_exists("get_web_page")) {
|
||||||
function get_web_page($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45) {
|
function get_web_page($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45) {
|
||||||
if(!in_array("curl", get_loaded_extensions())) {
|
if(!in_array("curl", get_loaded_extensions())) {
|
||||||
|
@ -13,26 +46,24 @@ if(!function_exists("get_web_page")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
CURLOPT_PROXY => "", // set proxy server
|
CURLOPT_PROXY => $proxy, // set proxy server
|
||||||
CURLOPT_RETURNTRANSFER => true, // return web page
|
CURLOPT_RETURNTRANSFER => true, // return web page
|
||||||
CURLOPT_HEADER => false, // don't return headers
|
CURLOPT_HEADER => false, // don't return headers
|
||||||
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
||||||
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
|
||||||
CURLOPT_ENCODING => "", // handle compressed
|
CURLOPT_ENCODING => "", // handle compressed
|
||||||
CURLOPT_USERAGENT => "", // name of client
|
CURLOPT_USERAGENT => $ua, // name of client
|
||||||
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
CURLOPT_AUTOREFERER => true, // set referrer on redirect
|
||||||
CURLOPT_CONNECTTIMEOUT => $ct_out, // time-out on connect
|
CURLOPT_CONNECTTIMEOUT => $ct_out, // time-out on connect
|
||||||
CURLOPT_TIMEOUT => $t_out, // time-out on response
|
CURLOPT_TIMEOUT => $t_out, // time-out on response
|
||||||
|
CURLOPT_FAILONERROR => true, // get error code
|
||||||
|
CURLOPT_SSL_VERIFYHOST => false, // ignore ssl host verification
|
||||||
|
CURLOPT_SSL_VERIFYPEER => false, // ignore ssl peer verification
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!empty($ua)) {
|
if(empty($options[CURLOPT_USERAGENT])) {
|
||||||
|
$ua = "2018 ReasonableFramework;https://github.com/gnh1201/reasonableframework";
|
||||||
$options[CURLOPT_USERAGENT] = $ua;
|
$options[CURLOPT_USERAGENT] = $ua;
|
||||||
} else {
|
|
||||||
$options[CURLOPT_USERAGENT] = "2018 ReasonableFramework;https://github.com/gnh1201/reasonableframework";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($proxy)) {
|
|
||||||
$options[CURLOPT_PROXY] = $proxy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($method == "post" && count($data) > 0) {
|
if($method == "post" && count($data) > 0) {
|
||||||
|
@ -53,13 +84,30 @@ if(!function_exists("get_web_page")) {
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
|
|
||||||
$content = curl_exec($ch);
|
$content = curl_exec($ch);
|
||||||
|
|
||||||
|
// if content is not string
|
||||||
|
$status = "-1";
|
||||||
|
$resno = "-1";
|
||||||
|
$errno = "-1";
|
||||||
|
|
||||||
|
if($content === true || $content === false) {
|
||||||
|
$content = get_web_cmd($url, $method, $data, $proxy, $ua, $ct_out, $t_out);
|
||||||
|
} else {
|
||||||
|
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$resno = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||||
|
$errno = curl_errno($ch);
|
||||||
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$content_size = strlen($content);
|
$content_size = strlen($content);
|
||||||
|
|
||||||
$response = array(
|
$response = array(
|
||||||
"content" => $content,
|
"content" => $content,
|
||||||
"size" => $content_size
|
"size" => $content_size,
|
||||||
|
"status" => $status,
|
||||||
|
"resno" => $resno,
|
||||||
|
"errno" => $errno,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user