2011-11-29 20 views
0

我需要你的幫助來創建簡單的PHP代碼的fopen或的fsockopen如何使用fopen或的fsockopen得到的反饋

我想http://www.projecthoneypot.org/ip_xx.xx.xx.xx 檢查IPS和得到反饋

例如:

的用戶IP地址爲127.0.0.1

現在,我將使用的fopen或到的fsockopen如果ckeck的projecthoneypot.org有關於它的任何信息或不

http://www.projecthoneypot.org/ip_127.0.0.1

如果「沒有對這個IP數據目前」回聲「無日期」其他「找到數據」

請幫

+0

和獲取日期?什麼約會? –

+0

那麼'fsockopen'會是創建HTTP請求的最糟糕的方式。請使用[curl](http://www.php.net/manual/en/function.curl-exec.php)或['file_get_contents'](http://ch2.php.net/manual/en/function .file-GET-contents.php)。後者需要啓用'allow_url_fopen'。 – vstm

+0

Jan Dragsbaek只需一分鐘,我會改進Q.thanks – Maroman

回答

0

嗯......簡單的代碼:

$response = file_get_contents("http://www.projecthoneypot.org/ip_127.0.0.1"); 
$match = preg_match("/don't have data on this IP currently/i", $response); 

if($match) { 
    echo "No Date"; 
} else { 
    echo "Data Was Found"; 
} 

或用捲髮:

$ch = curl_init(); 

curl_setopt_array($ch, array(
    CURLOPT_URL => 'http://www.projecthoneypot.org/ip_127.0.0.1', 
    CURLOPT_HEADER => false, 
    CURLOPT_RETURNTRANSFER => true, 
)); 

$response = curl_exec($ch); 
curl_close($ch); 

$match = preg_match("/don't have data on this IP currently/i", $response); 

if($match) { 
    echo "No Date"; 
} else { 
    echo "Data Was Found"; 
} 
+0

非常感謝vstm! 。我最誠摯的問候 – Maroman

0

我建議使用fsockopen,因爲它可以讓你輕鬆定義一個超時。但是它確實需要在配置中啓用套接字。

+0

謝謝Sudhir。你有任何簡單的PHP代碼可以做到這一點嗎? Regards – Maroman

相關問題