国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

php如何post發送數據

2024-04-25 20:35:53
字體:
來源:轉載
供稿:網友

function _mh_send($action, $data = null)

{

return $this->_ps_post(SHOP_PATH.'json.php?act=del_user', 500000, $data);

}

/**

* post數據

* @param string $url post的url

* @param int $limit 返回的數據的長度

* @param string $post post數據,字符串形式username='dalarge'&password='123456'

* @param string $cookie 模擬 cookie,字符串形式username='dalarge'&password='123456'

* @param string $ip ip地址

* @param int $timeout 連接超時時間

* @param bool $block 是否為阻塞模式

* @return string 返回字符串

*/

function _ps_post($url, $limit = 0, $post = '', $cookie = '', $ip = '', $timeout = 15, $block = true) {

$return = '';

$matches = parse_url($url);

$host = $matches['host'];

$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';

$port = !empty($matches['port']) ? $matches['port'] : 80;

$siteurl = $this->_get_url();

if($post) {

$out = "POST $path HTTP/1.1/r/n";

$out .= "Accept: */*/r/n";

$out .= "Referer: ".$siteurl."/r/n";

$out .= "Accept-Language: zh-cn/r/n";

$out .= "Content-Type: application/x-www-form-urlencoded/r/n";

$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]/r/n";

$out .= "Host: $host/r/n" ;

$out .= 'Content-Length: '.strlen($post)."/r/n" ;

$out .= "Connection: Close/r/n" ;

$out .= "Cache-Control: no-cache/r/n" ;

$out .= "Cookie: $cookie/r/n/r/n" ;

$out .= $post ;

} else {

$out = "GET $path HTTP/1.1/r/n";

$out .= "Accept: */*/r/n";

$out .= "Referer: ".$siteurl."/r/n";

$out .= "Accept-Language: zh-cn/r/n";

$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]/r/n";

$out .= "Host: $host/r/n";

$out .= "Connection: Close/r/n";

$out .= "Cookie: $cookie/r/n/r/n";

}

$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);

if(!$fp) return '';

stream_set_blocking($fp, $block);

stream_set_timeout($fp, $timeout);

@fwrite($fp, $out);

$status = stream_get_meta_data($fp);

if($status['timed_out']) return '';

while (!feof($fp)) {

if(($header = @fgets($fp)) && ($header == "/r/n" || $header == "/n")) break;

}

$stop = false;

while(!feof($fp) && !$stop) {

$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));

$return .= $data;

if($limit) {

$limit -= strlen($data);

$stop = $limit <= 0;

}

}

@fclose($fp);

//部分虛擬主機返回數值有誤,暫不確定原因,過濾返回數據格式

$return_arr = explode("/n", $return);

if(isset($return_arr[1])) {

$return = trim($return_arr[1]);

}

unset($return_arr);

return $return;

}

/**

* 獲取當前頁面完整URL地址

*/

function _get_url() {

$sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';

$php_self = $_SERVER['PHP_SELF'] ? $this->_safe_replace($_SERVER['PHP_SELF']) : $this->_safe_replace($_SERVER['SCRIPT_NAME']);

$path_info = isset($_SERVER['PATH_INFO']) ? $this->_safe_replace($_SERVER['PATH_INFO']) : '';

$relate_url = isset($_SERVER['REQUEST_URI']) ? $this->_safe_replace($_SERVER['REQUEST_URI']) : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$this->_safe_replace($_SERVER['QUERY_STRING']) : $path_info);

return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;

}

/**

* 安全過濾函數

*

* @param $string

* @return string

*/

function _safe_replace($string) {

$string = str_replace('%20','',$string);

$string = str_replace('%27','',$string);

$string = str_replace('%2527','',$string);

$string = str_replace('*','',$string);

$string = str_replace('"','&quot;',$string);

$string = str_replace("'",'',$string);

$string = str_replace('"','',$string);

$string = str_replace(';','',$string);

$string = str_replace('<','&lt;',$string);

$string = str_replace('>','&gt;',$string);

$string = str_replace("{",'',$string);

$string = str_replace('}','',$string);

$string = str_replace('//','',$string);

return $string;

}

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南木林县| 马尔康县| 沙坪坝区| 正蓝旗| 崇阳县| 加查县| 达孜县| 德州市| 商河县| 什邡市| 六安市| 古蔺县| 嘉鱼县| 宣威市| 唐海县| 昌黎县| 白玉县| 曲水县| 逊克县| 开原市| 西贡区| 中山市| 林甸县| 北川| 庆城县| 江西省| 昆明市| 明光市| 雅江县| 隆安县| 东丰县| 临沧市| 神池县| 新绛县| 临安市| 门源| 日照市| 塔城市| 江山市| 阜新| 遂川县|