LiteSite/跨網站觸動:修訂版本之間的差異

出自六年制學程
跳轉到: 導覽搜尋
(二)方法二
 
第 8 行: 第 8 行:
 
  $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";
 
  $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所連線的電腦
 
  socket_write($socket,$command,strlen($command)); // 將$command的內容送給$socket所連線的電腦
  $content=''; // 回應字串
+
  $content=''; // 回應字串
 
  while($response=socket_read($socket,1024)){$content.=$response;} // 讀取回應
 
  while($response=socket_read($socket,1024)){$content.=$response;} // 讀取回應
 
  socket_close($socket); // 關閉連線
 
  socket_close($socket); // 關閉連線

2019年12月7日 (六) 10:51的最新修訂版本

一、方法

(一)方法一

$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); 					// 關閉連線