小赖子的英国生活和资讯

phpbb3.15 论坛下 网络爬虫出错的解决方法

阅读 桌面完整版

最近把我的英文算法论坛给升级到PHPBB3.15可是就发现网络爬虫 e.g. GOOGLEBOT 在浏览论坛的时候其实是会报错的.

phpbb-general-error-for-bots phpbb3.15 论坛下 网络爬虫出错的解决方法 小技巧 技术 折腾 程序设计

phpbb-general-error-for-bots

可以用第三方网络 sniffer 或者用 CHROME的一个 user agent switcher 的插件把 user agent 设置成:

Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

这是由 /forum/phpbb/user.php 文件的第 235 行有错误引起的.

1
2
3
4
5
6
7
    $sql = 'SELECT *
    FROM ' . STYLES_TABLE . " s
    WHERE s.style_id = $style_id";
           
    $result = $db->sql_query($sql, 3600);
    $this->style = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
	$sql = 'SELECT *
 	FROM ' . STYLES_TABLE . " s
	WHERE s.style_id = $style_id";
           
	$result = $db->sql_query($sql, 3600);
	$this->style = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

很明显 当变量 $style_id 为空时, SQL 就有语法错误. 最简单的方法就是把这个变量用单引号框起来:

1
2
3
4
5
6
7
    $sql = 'SELECT *
    FROM ' . STYLES_TABLE . " s
    WHERE s.style_id = '$style_id'";
           
    $result = $db->sql_query($sql, 3600);
    $this->style = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
	$sql = 'SELECT *
	FROM ' . STYLES_TABLE . " s
	WHERE s.style_id = '$style_id'";
           
	$result = $db->sql_query($sql, 3600);
	$this->style = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

或者在这之前加一句判断:

1
if (!$style_id) $style_id = 0;
if (!$style_id) $style_id = 0;

当然最好把 表名, 表字段用 ` 框起来, 这些都是良好编程的习惯.

英文: https://helloacm.com/how-to-fix-phpbb3-1-5-general-error-for-bots/

强烈推荐

微信公众号: 小赖子的英国生活和资讯 JustYYUK

阅读 桌面完整版
Exit mobile version