本文整理匯總了PHP中Sms::_get_url方法的典型用法代碼示例。如果您正苦於以下問題:PHP Sms::_get_url方法的具體用法?PHP Sms::_get_url怎麽用?PHP Sms::_get_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sms
的用法示例。
在下文中一共展示了Sms::_get_url方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _post
/**
* 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 返回字符串
*/
private function _post($url, $limit = 0, $post = '', $cookie = '', $ip = '', $timeout = 15, $block = true)
{
$return = '';
$url = str_replace('&', '&', $url);
$matches = parse_url($url);
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'] . ($matches['query'] ? '?' . $matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : 80;
$siteurl = Sms::_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);
var_export($return);
exit;
//部分虛擬主機返回數值有誤,暫不確定原因,過濾返回數據格式
$return_arr = explode("\n", $return);
if (isset($return_arr[1])) {
$return = trim($return_arr[1]);
}
unset($return_arr);
return $return;
}