fsockopen读写文件

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; 
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值