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/

GD Star Rating
loading...
本文一共 175 个汉字, 你数一下对不对.
phpbb3.15 论坛下 网络爬虫出错的解决方法. (AMP 移动加速版本)
上一篇: One Day Visit to Fen Drayton Lake - 村庄附近的 Fen Drayton 湖
下一篇: 一日剪头,三日烟岛(在英国理发)

扫描二维码,分享本文到微信朋友圈
4da75d113877a5225bd26ad6ca5b4522 phpbb3.15 论坛下 网络爬虫出错的解决方法 小技巧 技术 折腾 程序设计

评论