Problem with code to show ads to search engine visitors only

There is a plugin (for wordpress) to show ads to search engine visitors only.. a person was able to modify it
but the code only shows ads if you land and click another page…but it doesnt appear on the landing page. Can anyone help me know whats wrong on the code?

function wp_ozh_wsa_is_fromsearchengine($doset = false) {
global $wp_ozh_wsa;
$ref = $_SERVER['HTTP_REFERER'];
$yes = false;
if (isset($wp_ozh_wsa['my_search_engines'])) {
    $SE = $wp_ozh_wsa['my_search_engines'];
} else {
    $SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search',
    'soso.com', '/search/', '.yahoo.',
    );
}
foreach ($SE as $url) {
    if (strpos($ref,$url)!==false) {
        if ($doset) {
            $url = parse_url(get_option('home'));
            setcookie('wsas', 'yes', time() + 60*60, $url['path'] . '/');
        }
    }
}
if (isset($_COOKIE['wsas'])) {
    return true;
}
return false;
}

Related posts

Leave a Reply

1 comment

  1. As Stated in the ref for setcookie on php.net:

    Once the cookies have been set, they
    can be accessed on the next page load
    with the $_COOKIE or $HTTP_COOKIE_VARS
    arrays.

    Simple fix, just add the following to your foreach:

    foreach ($SE as $url) {
        if (strpos($ref,$url)!==false) {
            if ($doset) {
                $url = parse_url(get_option('home'));
                setcookie('wsas', 'yes', time() + 60*60, $url['path'] . '/');
                return true;
            }
        }
    }