LiteSite/跨網站觸動

出自六年制學程
跳轉到: 導覽搜尋

一、方法

(一)方法一

$content=file_get_contents($url);

(二)方法二

$socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);	// 產生插座
$connection=socket_connect($socket,$host,80);		// 插座連到 host
$command="GET ".substr($_SERVER['REQUEST_URI'],strpos($_SERVER['REQUEST_URI'],$_SERVER['SCRIPT_NAME'])+strlen($_SERVER['SCRIPT_NAME'])).(strstr($_SERVER['REQUEST_URI'],'?')?'&':'?')."action=render HTTP/1.0\nhost:".$host."\n\n";
socket_write($socket,$command,strlen($command)); 	// 將$command的內容送給$socket所連線的電腦
$content=''; // 回應字串
while($response=socket_read($socket,1024)){$content.=$response;} // 讀取回應
socket_close($socket); 					// 關閉連線