开发者

Extract IP from header using php

OK I'm not great with PHP but I'm learning so stay with me here.

I have an email address that all email received is piped to a php script which then stores the headers message subject etc in a database.

This works Fine but what I need to do is search the header for the senders server IP and then put that into a variable.

开发者_开发技巧From originalguy@someplace.com Sun Dec 12 02:37:01 2010
Received: from mail-pz0-f52.google.com ([**209.85.210.52**])
        by some.server.com with esmtp (Exim 4.69) (envelope-from <razz222au@gmail.com>)
        id 1PRRVJ-00020U-1p for someguy@someplace.com;


You can use regular expressions to parse the Received headers. You want to look for the first one, which will be the last one down from the top. Unless some are spoofed, which is common in spams.


Use regular expressions.

i.e.

if (preg_match('/\(\[((\d){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3})\]\)/i', $string, $matches))
{
    print_r($matches);
}
  • Christian
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜