function gernerateFreeHero($links){
$heros = array();
foreach($links as $key=>$val){
$item = explode(',',$val);
$heros[$key]['key'] = $item[0];
$heros[$key]['name'] = $item[1];
$heros[$key]['title'] = $item[2];
$heros[$key]['url'] = $item[3];
}
//var_dump($heros);
$poststr = rtrim($this->dataEncode($heros), '&');
$fp = fsockopen('www.xxx.com', 80, $errno, $errstr, 10) or die('无法连接到服务器');
fwrite($fp, "POST /index.php HTTP/1.1\r\n");
fwrite($fp, "Host: www.xxx.com\r\n");
fwrite($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($fp, "Content-Length: ".strlen($poststr)."\r\n");
fwrite($fp, "Connection: close\r\n\r\n");
fwrite($fp, $poststr."\r\n\r\n");
$result = '';
$isconter = false;
$len = 0;
while($str=fgets($fp))
{
if($isconter==true) $result .= $str;
else if($str=="\r\n")
{
$isconter = true;
if($_SERVER['SERVER_SOFTWARE']!='Microsoft-IIS/6.0') $len = hexdec(fgets($fp));
}
}
fclose($fp);
if($_SERVER['SERVER_SOFTWARE']!='Microsoft-IIS/6.0') $result = substr($result, 0, $len);
if($result == 'true'){
echo '成功';
exit();
}else{
echo '失败';
exit();
}
}
function dataEncode($data, $keyprefix = '', $keypostfix = '')
{
assert(is_array($data));
$vars = '';
foreach ($data as $key => $value)
{
if (TRUE == is_array($value)) $vars .= $this->dataEncode($value, $keyprefix . $key . $keypostfix . urlencode('['), urlencode(']'));
else $vars .= $keyprefix . $key . $keypostfix . '='.urlencode($value) . '&';
}
// if ('' != $vars) $vars = substr($vars, 0, -1);
return $vars;
}
//object转array
function object_to_array($obj)
{
$_arr= is_object($obj) ? get_object_vars($obj) : $obj;
foreach($_arr as $key=> $val)
{
$val= (is_array($val) || is_object($val)) ? $this->object_to_array($val) : $val;
$arr[$key] = $val;
}
return$arr;
}