Recap and Solution I Implemented in v2.0.7 for the Meantime:
Problem:
During testing, I faced difficulties with the spider detection feature in Zen Cart. Specifically, the utilization of the $spider_flag variable did not produce the expected results, particularly in generating logs after detecting a spider using:
PHP Code:
if (isset($spider_flag) && $spider_flag === true)
Solution Implemented:
To resolve this issue, I decided to clone the spider detection code from Zen Cart and integrate it directly into the module functions file. This allowed me to incorporate the spider detection functionality without relying on Zen Cart's $spider_flag variable. As a result, the spider detection now works as intended within my custom code.
PHP Code:
function checkSpiderFlag() {
if (defined('SESSION_BLOCK_SPIDERS')) {
$user_agent_abuseipdb = '';
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$user_agent_abuseipdb = strtolower($_SERVER['HTTP_USER_AGENT']);
}
$spider_flag_abuseipdb = false;
if (!empty($user_agent_abuseipdb)) {
$spiders_abuseipdb = file(DIR_WS_INCLUDES . 'spiders.txt');
for ($i = 0, $n = sizeof($spiders_abuseipdb); $i < $n; $i++) {
if (!empty($spiders_abuseipdb[$i]) && substr($spiders_abuseipdb[$i], 0, 4) != '$Id:') {
if (is_integer(strpos($user_agent_abuseipdb, trim($spiders_abuseipdb[$i])))) {
$spider_flag_abuseipdb = true;
break;
}
}
}
}
return $spider_flag_abuseipdb;
}
return false;
Although the current solution successfully resolves the logging problem, I am interested in understanding why using the original $spider_flag variable did not produce the expected outcome. If anyone has any insights, suggestions, or guidance that could be a potential resolution that would allow me to revert back to using the $spider_flag in the future, please do let me know!
Thank you for your time and assistance.
Bookmarks