Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow other modules to check the user agent and change the "is bot" result if desired #24

Merged
merged 2 commits into from Dec 20, 2018

Conversation

kanevbg
Copy link
Contributor

@kanevbg kanevbg commented Dec 15, 2018

This gives developer an possibility to change easily on per-project basis what is a bot visitor.

@kanevbg
Copy link
Contributor Author

kanevbg commented Dec 15, 2018

ah... that is a lib meant to be magento independent ..

The new solution uses PHP only. To set additional custom method for checking the user agent and decide if it is bot use:

parent::$_botCheckCallback = [$this, '_isBotAgent'];

Before constructing \Cm\RedisSession\Handler:

        parent::__construct(
            new Cm_RedisSession_Model_Session_Config(),
            new Cm_RedisSession_Model_Session_Logger()
        );
@kanevbg
Copy link
Contributor Author

kanevbg commented Dec 15, 2018

\Cm\RedisSession\Handler::$_botCheckCallback = [$myCheker, 'userAgentBotCheckCallback'];
This is example usage. Sets the callback for the bot checking. It should be set before using \Cm\RedisSession\Handler

Example function for callback may be:

public function userAgentBotCheckCallback($userAgent, $isBot)
{
if (!$isBot) {
if (preg_match('/^CustomCrawlerName/i', $userAgent)) {
$isBot = true;
}
}
return $isBot;
}

@colinmollenhour colinmollenhour merged commit 266374f into colinmollenhour:master Dec 20, 2018
@colinmollenhour
Copy link
Owner

Thanks!

@kanevbg
Copy link
Contributor Author

kanevbg commented Dec 20, 2018

Thank u 2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants