Search-Log?

Hi,

first of all - thanks for Zenphoto - its a great piece of Software!

I like to Log the Users searches on my Zenphoto-Site. I made it the easy way and
added an SQL-Insert on the search.php which saves the searchwords and the number of pictures which were returned into a table.

My problem is that every time i search something and click on a result, the searchterm gets stored 2-3 times.

Maybe you know why this happens? Or do you know an more elegant way to implement a search-Log or have some tipps?

Thanks in advace

Comments

  • I am not exactly sure I understand what you have done, but here is a comment based on this interpretation that you have put the search saving code in your theme's search.php page.

    Each time the page gets loaded your code will be run. So, it will be run when page 1 is displayed, when page 2 is displayed, etc. You can test the page number and only record the search when page 1 is shown. That will reduce the number of times it gets stored. You could also come up with some sort of hash code for a particular search based on the IP address and whatever else you might find that indicate it is a unique search. Then you could see if the hash already existed and not store if it does.
  • fuzzi Member
    Hi sbillard,

    thanks for you answer. I see that putting the code in the search.php is not the best solution. I also have the problem that i also get all the clicks on tags as search-requests. But i am only interrested in the real search-requests entered by the users so i can improve my gallerys over time.

    So it will be better to catch the data entered into the search-textfield and write it to the db. But i dont know how to catch the data because the action of the search form is /page/search.

    Do you know a way how i can accomplish this task?

    Thanks a lot in advance!
  • The only difference in a search entered by a user on the form and any other use of the search is that the search form does a "POST" action to access search.php. You can make a test `if(isset($_POST['searchwords']) {` to see if the page was entered by a "POST" action and place your code there. If you place this code after the point where `$searchwords` is retrieved then `$searchwords` will contain the search the user entered.

    One advantage of this is that you only get the "POST" on the initial page, the clicks on next/previous pages all use query parameters.
  • fuzzi Member
    Hi sbillard,

    thanks a lot for your time for helping me. I tried it the way you wrote but it doesnt work for me. It doesnt matter where i place the following code:

    `

    if (isset($_POST['searchwords'])){

    echo "

    real search

    ";

    }else {echo "click on tags"; }

    ?>

    `

    I always get a "click on tags"?

  • Sorry, It should be `if (isset($_POST['words'])) {`
  • fuzzi Member
    now it works - great :)

    Thanks a lot for your help and for investing so much time in developing zenphoto!
Sign In or Register to comment.