• Resolved saphod

    (@saphod)


    Hi,

    if I wanted to log the requesting IP-address for stats, which action hook in WordPress would you recommend?

    init?
    template_redirect?
    wp_header?

    It would be nice if you shortly explained your choice.
    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I think maybe it depends on the stats you want to keep… personally, I’d hook the footer, because there’s no reason to insert yourself in the process of displaying the page, if your plugin does nothing to affect what follows.

    if you’re just snooping on the process, then do so after the content is done.

    I certainly wouldn’t do it before a template is chosen, or before the URL is formed, etc… otherwise how will you know what to log the hit against?

    Thread Starter saphod

    (@saphod)

    Hmm. Sounds to me that you’d go for wp_header if you had to choose… that’s what I thought. I suppose it’s as good as wp_footer.

    Uh, I thought even starting with init, the URL was already formed?

    Thanks for the quick answer.

    Funny it’s always you. ??
    Greetz to Melbourne!

    The URL is always formed, as you’re requesting it before anything happens. I was speaking more in the abstract. Not having any idea of the kind of stats you want to keep, I guess you might want to allow for redirections at the template level, or you might even want to keep statistical information about the queries which are formed as you go… I dunno, it’s irrelevant to your question, so I didn’t really explore it.

    As you noticed, I didn’t even respond do your question directly. I have a way of not doing that. Sorry about that.

    Yes, of those choices I’d use the header.

    Cheers ??

    Thread Starter saphod

    (@saphod)

    Just want to keep the IP, the URL and the referer for antispam measures… and in some way, you did respond. ??

    Thread Starter saphod

    (@saphod)

    Here is the difference between “init” and “wp_head” (not wp_header, that was wrong) as I found:

    As “init” hooks in earlier, you can actually grab a “REQUEST_URI” that does not lead to a post or page only but to any URL on your blog. Since I wanted to find out about spambots, I can see a lot of hits when I use “init” pointing to e.g. “wp-comments.php” or trying to exploit “wp-pass.php”.

    “wp_head” only works if posts or pages are viewed – sufficient for blog statistics, but not to get IPs from spambots to block because calls to “wp-comments.php” would not appear in a log created within “wp_head”.

    yeah, I think the landscape of your question changes dramatically when you say “antispam”, while blog stats information may actively wish to ignore that data.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Which action hook to use?’ is closed to new replies.