如何使用fopen或fsockopen获取反馈

时间:2011-11-29 16:01:26

标签: php fopen fsockopen

我需要你的帮助来用fopen或fsockopen

创建简单的php代码

我想通过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的数据”回显“没有日期”,否则“找到数据”

请帮忙

2 个答案:

答案 0 :(得分:0)

我建议使用fsockopen,因为它允许您轻松定义超时。但是它确实需要在配置中启用套接字。

答案 1 :(得分: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";
}