Log your visitors search queries in WordPress

Discussion in 'WordPress' started by Kerosene, Jul 17, 2006.

  1. #1
    Anyone using a WordPress theme with a search.php (e.g WordPress Default) might be interested in this...

    I wanted to see what my visitors were searching for, so I worked out a simple way to write their queries to a txt file.

    Just whack this in your search.php file (in your theme directory), put it under the <?php get_header(); ?> line:

    <?php 
    $mydate =  date('d F Y H:i:s -');
    $mydata = "$mydate $s\n";
    $x = fopen("saved_searches.txt", "a");
    fwrite($x, $mydata);
    fclose($x);
    ?>
    
    Code (markup):
    You'll need to create the initial empty saved_seaches.txt file in your WP directory, and chmod it to 777 (I think). And or course you'll have to be hosting your own WP installation.

    If all goes to plan you should end up with a txt file full of this sort of garbage:
    18 July 2006 02:17:35 - katamari
    18 July 2006 02:50:36 - banana
    18 July 2006 02:50:52 - egg
    18 July 2006 02:51:34 - egg2
    18 July 2006 02:52:35 - test

    Any php nerds know if doing this has any security implications?
     
    Kerosene, Jul 17, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If it is in an unprotected directory and chmod'd to 777, anyone will be able to view it. I would at the least put the file in a protected directory.
     
    jestep, Jul 17, 2006 IP
  3. SFOD_D223

    SFOD_D223 Peon

    Messages:
    4,512
    Likes Received:
    174
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You see..there are plenty of PHP helpers around DP..YAY!!
     
    SFOD_D223, Jul 17, 2006 IP
  4. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
    #4
    You can do this more efficiently (and more safely) using the WordPress bsuite plugin.
     
    minstrel, Jul 17, 2006 IP
  5. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #5
    All the plugins I looked at did way too many other things I didn't need or want.

    Other than people being able to view the txt file if it's not in a protected dir (which isn't a big deal) - what are the safety issues in what I'm doing?
     
    Kerosene, Jul 17, 2006 IP
  6. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
    #6
    That is the safety issue. But beyond that, your method is more cumbersome and the plugin I mentioned willl give you not only search terms but the referrer information as well, nicely summarized.

    If you're happy with it, I'm not trying to put you down for that. Just pointing out for others that there are existing packages out there (including but not limioted to bsuite) that will do what your mod does and won't need to be redone with updates to Wordpress such as the upcoming version 2.04).

    It's always nice to have choice. :)
     
    minstrel, Jul 17, 2006 IP
  7. stressbattle

    stressbattle Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Does bSuite helps in SEO or getting more traffic from Search Engines?
     
    stressbattle, Aug 23, 2006 IP
  8. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
    #8
    No. It's primarily just a stats package,
     
    minstrel, Aug 23, 2006 IP
  9. sometemple

    sometemple Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    sweet. thanks for this, guys
     
    sometemple, Aug 23, 2006 IP