Update webpagetool.php
This commit is contained in:
parent
ce1e01dd46
commit
c4f3bb13df
|
@ -31,18 +31,20 @@ if(!function_exists("get_web_cmd")) {
|
||||||
$cmd = "";
|
$cmd = "";
|
||||||
|
|
||||||
if($method == "get") {
|
if($method == "get") {
|
||||||
$cmd = "curl -A '%s' -k %s";
|
$cmd = "curl -A '%s' -k '%s'";
|
||||||
$cmd_fin = sprintf($cmd, addslashes($ua), addslashes($url));
|
$cmd_fin = sprintf($cmd, addslashes($ua), addslashes(get_web_build_qs($url, $data)));
|
||||||
$output = shell_exec($cmd_fin);
|
$output = shell_exec($cmd_fin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($method == "post") {
|
if($method == "post") {
|
||||||
$cmd = "curl -X POST -A '%s' -k %s %s";
|
$cmd = "curl -X POST -A '%s' -k '%s' %s";
|
||||||
$params_cmd = "";
|
$params_cmd = "";
|
||||||
foreach($data as $k=>$v) {
|
foreach($data as $k=>$v) {
|
||||||
$k = addslashes($v);
|
if(substr($v, 0, 1) == "@") { // if file
|
||||||
$v = addslashes($v);
|
$params_cmd .= sprintf("-F '%s=%s' ", addslashes($k), addslashes($v));
|
||||||
$params_cmd .= "-d '{$k}={$v}' ";
|
} else {
|
||||||
|
$params_cmd .= sprintf("-d '%s=%s' ", addslashes($k), addslashes($v));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$cmd_fin = sprintf($cmd, addslashes($ua), addslashes($url), $params_cmd);
|
$cmd_fin = sprintf($cmd, addslashes($ua), addslashes($url), $params_cmd);
|
||||||
$output = shell_exec($cmd_fin);
|
$output = shell_exec($cmd_fin);
|
||||||
|
@ -54,11 +56,20 @@ if(!function_exists("get_web_cmd")) {
|
||||||
|
|
||||||
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) {
|
||||||
|
$status = "-1";
|
||||||
|
$resno = "-1";
|
||||||
|
$errno = "-1";
|
||||||
|
|
||||||
|
if($method = "post.cmd" || $method == "get.cmd") {
|
||||||
|
$content = get_web_cmd($url, $method, $data, $proxy, $ua, $ct_out, $t_out);
|
||||||
|
echo $content;
|
||||||
|
} else {
|
||||||
if(!in_array("curl", get_loaded_extensions())) {
|
if(!in_array("curl", get_loaded_extensions())) {
|
||||||
return "cURL extension needs to be installed.";
|
return "cURL extension needs to be installed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
|
CURLOPT_URL => $url, // set url
|
||||||
CURLOPT_PROXY => $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
|
||||||
|
@ -85,21 +96,17 @@ if(!function_exists("get_web_page")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if($method == "get" && count($data) > 0) {
|
if($method == "get" && count($data) > 0) {
|
||||||
$url = get_web_build_qs($url, $data);
|
$options[CURLOPT_URL] = get_web_build_qs($url, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init();
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
|
|
||||||
$content = curl_exec($ch);
|
$content = curl_exec($ch);
|
||||||
|
if(!is_string($content)) {
|
||||||
// if content is not string
|
$res_method = $method . ".cmd";
|
||||||
$status = "-1";
|
$res = get_web_page($url, $res_method, $data, $proxy, $ua, $ct_out, $t_out);
|
||||||
$resno = "-1";
|
$content = $res['content'];
|
||||||
$errno = "-1";
|
|
||||||
|
|
||||||
if($content === true || $content === false) {
|
|
||||||
$content = get_web_cmd($url, $method, $data, $proxy, $ua, $ct_out, $t_out);
|
|
||||||
} else {
|
} else {
|
||||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
$resno = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
$resno = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||||
|
@ -107,6 +114,7 @@ if(!function_exists("get_web_page")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
}
|
||||||
|
|
||||||
$content_size = strlen($content);
|
$content_size = strlen($content);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user