<?php
/**
* SOCKET扩展函数
* @copyright (c) 2013
* @author Qiufeng <fengdingbo@gmail.com>
* @link http://www.1sucai.cn
* @version 1.0
*/
/**
* Post Request
*
* @param string $url
* @param array $data
* @param string $referer
* @return array
*/
if ( ! function_exists('socket_post'))
{
function socket_post($url, $data, $referer='')
{
if( ! is_array($data))
{
return;
}
$data = http_build_query($data);
$url = parse_url($url);
if ( ! isset($url['scheme']) || $url['scheme'] != 'http')
{
die('Error: Only HTTP request are supported !');
}
$host = $url['host'];
$path = isset($url['path']) ? $url['path'] : '/';
// open a socket connection on port 80 - timeout: 30 sec
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if ($fp)
{
// send the request headers:
$length = strlen($data);
$POST = <<<HEADER
POST {$path} HTTP/1.1
Accept: text/plain, text/html
Referer: {$referer}
Accept-Language: zh-CN,zh;q=0.8
Content-Type: application/x-www-form-urlencodem
Cookie: token=value; pub_cookietime=2592000; pub_sauth1=value; pub_sauth2=value
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17
Host: {$host}
Content-Length: {$length}
Pragma: no-cache
Cache-Control: no-cache
Connection: closern
{$data}
HEADER;
fwrite($fp, $POST);
$result = '';
while(!feof($fp))
{
// receive the results of the request
$result .= fread($fp, 512);
}
}
else
{
return array(
'status' => 'error',
'error' => "$errstr ($errno)"
);
}
// close the socket connection:
fclose($fp);
// split the result header from the content
$result = explode("rnrn", $result, 2);
// return as structured array:
return array(
'status' => 'ok',
'header' => isset($result[0]) ? $result[0] : '',
'content' => isset($result[1]) ? $result[1] : ''
);
}
}
print_r(socket_post('http://www.1sucai.cn/', array('name='=>'qiufeng','password'=>md5('www.1sucai.cn'))));
/* e.g: socket_post('http://www.1sucai.cn', array('name='=>'qiufeng','password'=>md5('jb51.net'))); */
/* End of file socket_helper.php */
<?php
$remote_server = "jb51.net";
$boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
// Build the header
$header = "POST /api.php?action=twupload HTTP/1.0rn";
$header .= "Host: {$remote_server}rn";
$header .= "Content-type: multipart/form-data, boundary=$boundaryrn";
/*
// attach post vars
foreach($_POST AS $index => $value){
$data .="--$boundaryrn";
$data .= "Content-Disposition: form-data; name="".$index.""rn";
$data .= "rn".$value."rn";
$data .="--$boundaryrn";
}
*/
$file_name = "aaa.jpg";
$content_type = "image/jpg";
$data = '';
// and attach the file
$data .= "--$boundaryrn";
$content_file = file_get_contents('aaa.jpg');
$data .="Content-Disposition: form-data; name="userfile"; filename="$file_name"rn";
$data .= "Content-Type: $content_typernrn";
$data .= "".$content_file."rn";
$data .="--$boundary--rn";
$header .= "Content-length: " . strlen($data) . "rnrn";
// Open the connection
$fp = fsockopen($remote_server, 80);
// then just
fputs($fp, $header.$data);
// reader
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有