fsockopen 읽기 및 쓰기 파일

2724 단어 open
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
"); fwrite($fp, "Host: www.xxx.com\r
"); fwrite($fp, "Content-type: application/x-www-form-urlencoded\r
"); fwrite($fp, "Content-Length: ".strlen($poststr)."\r
"); fwrite($fp, "Connection: close\r
\r
"); fwrite($fp, $poststr."\r
\r
"); $result = ''; $isconter = false; $len = 0; while($str=fgets($fp)) { if($isconter==true) $result .= $str; else if($str=="\r
") { $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; 
	}

좋은 웹페이지 즐겨찾기