PHP Search Keyword Detector

PHP Search Keyword Detector

Released 7 years ago , Last update 7 years ago

Use PHP Search Keyword Detector to detect what search engine your visitors used to reach you and with what keywords.

PHP Search Keyword Detector is a script that will detect if a referrer url is from a search engine and extract the search keyword from it.

Tracker scripts, administration interface and crons to gather and analyze data are provided in the package.


14 day 14-day money-back guarantee


Personal License

  • Perpetual license

  • 1 site, unlimited servers

  • No distribution (hosted use only)

  • Commercial use

Basic Usage

Here is the basic usage:

require_once( dirname(dirname(__FILE__)) . '/library/SearchKeyword.php' );

$url = '';

$detector = new SearchKeyword();

$searchKeyword = $detector->detect($url);

if (!is_null($searchKeyword)) {
    echo 'Detected search keyword: ' . $searchKeyword;
} else {
    echo 'No search keyword detected.';


For detector class

  • PHP 5

For admin interface and crons

  • PHP 5
  • MySql server
  • MySql extension for PHP
  • MySqli extension for PHP (optional)
  • Linux crontabs access


  • over 90% of search traffic detected
  • UTF-8 support
  • detects AJAX searches as well
  • designed for large traffic websites
  • advanced live/daily/monthly statistics
  • detailed log file provided for crons

Search engines suported

The following search engines are detected:

  • Google (including foreign domains, Google Images and Ajax search)
  • Yahoo
  • Bing
  • Facebook
  • Baidu
  • Ask
  • Yandex
  • Soso
  • Aol
  • Lycos
  • Mywebsearch


In order to support large number of search keywords (tested with over 200,000 keywords / day) and to reduce the load on the system that real-time queries would introduce, crons are used for cpu intensive tasks:

  • Log parse
  • Statistics

In order to activate the crons, you need to configure crontab on the system by using "crontab -e" and add the following (please note that absolute paths need to be used, so make sure you edit them first):

*/15 * * * * php -f /path/to/SearchKeyword/Cron/Log/Parse.php >>/path/to/SearchKeyword/_internal/log/log_parse.log 2>&1
1 1 * * * php -f /path/to/SearchKeyword/Cron/Statistics/Daily.php >>/path/to/SearchKeyword/_internal/log/statistics_daily.log 2>&1
1 2 * * * php -f /path/to/SearchKeyword/Cron/Cleanup/Keywords.php >>/path/to/SearchKeyword/_internal/log/cleanup_keywords.log 2>&1

Example log file

Each cron has its own log which can be found in /path/to/SearchKeyword/internal/log/. Please note that the information written in the log file is filtered based on the log level setting from trackerconfig.php.

19.09.2011 23:14:19|5112| 0.56MB|Bootstrap.php       |65 |INFO   |Running cron Log_Parse
19.09.2011 23:14:19|5112| 0.56MB|Parse.php           |208|DEBUG  |Process search file
19.09.2011 23:14:19|5112| 0.59MB|Parse.php           |222|INFO   |Processed 13 lines
19.09.2011 23:14:19|5112| 0.59MB|Parse.php           |348|DEBUG  |Using keyword buffer to insert in database
19.09.2011 23:14:19|5112| 0.58MB|Bootstrap.php       |158|INFO   |Total duration: 0.010736s
19.09.2011 23:14:19|5112| 0.58MB|Bootstrap.php       |162|INFO   |Min Memory: 0.49MB Max Memory: 0.59MB


The main configuration file is located in library/tracker_config.php.

Please note that a database connection is needed for the crons and admin interface provided. The database creation scripts for MySql are provided in DbScripts/MySql/ directory.

The following directories need write permissions for the user Apache runs under and for the one crons run under. Usually the same user should be used for both and should also own the project files.

chmod 775 _internal/log/
chmod 775 _internal/tmp/

Configuration parameters

$trackerConfig = array(
'tracker_file' => dirname(__FILE__) . '/keyword_tracker.log', 
'separator' => '|', // items separator in tracker file
'referrer' => isset($trackerReferrerUrl) ? $trackerReferrerUrl : null,  // set the referrer manually, useful for testing

// admin interface parameters
'admin_username' => 'admin', // username for admin interface
'admin_password' => 'trackeradmin', // password for admin interface
'admin_cookie_lifetime' => 1209600, // number of seconds to keep admin session (default: 2 weeks), set null to disable cookies
'admin_date_format' => 'Y-m-d H:i:s', // date format, please see date() format parameters -
'admin_max_lines' => 50, // maximum numbers of lines to retrieve from the tracker log file
'admin_timezone' => 'EST', // the timezone used to format dates, please see for allowed values
'admin_table_items' => 20, // the number of items to display on each page for admin tables

// database connection parameters
'db_connection' => array(
    // database connection parameters
    'adapter' => 'mysql', // database adapter to use, allowed: mysql, mysqli
    'host' => 'localhost', // the sql server host name or ip
    'username' => 'root', // the username used to connect to the database
    'password' => '', // the password used to connect to the database
    'dbname' => 'SEARCH_KEYWORD', // the database name
    'charset' => 'utf8' // charset to use for connection

// parse cron parameters
'cron_parse' => array(
    'buffer_size' => 100000 // buffer size - maximum number of records to hold in memory before executing queries

// cleanup cron parameters
'cron_cleanup' => array(
    'days_to_keep' => 30 // days to keep keywords in database

// logging settings
'log_directory' => dirname(dirname(__FILE__)) . '/_internal/log/',
'log_level' => 'DEBUG' // allowed values: DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, EMERG


To view all of the available class methods take a look at the API reference.

To view the documentation for the PhpLight library included take a look at the PhpLight API reference

2 licenses, starting from From » $9.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.

Or enter your name and Email
  • U utkarsh 1 year ago
  • U utkarsh 1 year ago
    this is a good site