1.通過curl函數
$post_data = array();<br />$post_data['clientname'] = "test08";<br />$post_data['clientpasswd'] = "test08";<br />$post_data['submit'] = "submit";<br />$url='http://xxx.xxx.xxx.xx/xx/xxx/top.php';<br />$o="";<br />foreach ($post_data as $k=>$v)<br />{<br /> $o.= "$k=".urlencode($v)."&";<br />}<br />$post_data=substr($o,0,-1);<br />$ch = curl_init();<br />curl_setopt($ch, CURLOPT_POST, 1);<br />curl_setopt($ch, CURLOPT_HEADER, 0);<br />curl_setopt($ch, CURLOPT_URL,$url);<br />//為了支援cookie<br />curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');<br />curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);<br />$result = curl_exec($ch);
2.通過fsockopen
$URL=‘http://xxx.xxx.xxx.xx/xx/xxx/top.php';<br />$post_data['clientname'] = "test08";<br />$post_data['clientpasswd'] = "test08";<br />$post_data['submit'] = "ログイン";<br />$referrer="";<br />// parsing the given URL<br />$URL_Info=parse_url($URL);<br />// Building referrer<br />if($referrer=="") // if not given use this script as referrer<br />$referrer=$_SERVER["SCRIPT_URI"];</p><p>// making string from $data<br />foreach($post_data as $key=>$value)<br />$values[]="$key=".urlencode($value);</p><p>$data_string=implode("&",$values);<br />// Find out which port is needed - if not given use standard (=80)<br />if(!isset($URL_Info["port"]))<br />$URL_Info["port"]=80;<br />// building POST-request:<br />$request.="POST ".$URL_Info["path"]." HTTP/1.1/n";<br />$request.="Host: ".$URL_Info["host"]."/n";<br />$request.="Referer: $referrer/n";<br />$request.="Content-type: application/x-www-form-urlencoded/n";<br />$request.="Content-length: ".strlen($data_string)."/n";<br />$request.="Connection: close/n";<br />$request.="/n";<br />$request.=$data_string."/n";<br />$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);<br />fputs($fp, $request);<br />while(!feof($fp)) {<br /> $result .= fgets($fp, 128);<br />}<br />fclose($fp);