xoops: 2.3.3
newbb: 4.00
表现:无论是普通会员还是管理员,在回复帖子时均显示Array(), 再次刷新后会告知session可能失效或过期。
打开查错后,发现有问题的sql语句如下:
INSERT INTO `bb_posts` (`topic_id`, `forum_id`, `post_time`, `poster_ip`, `poster_name`, `subject`, `pid`, `uid`, `icon`, `attachsig`, `approved`, `post_karma`, `require_reply`) VALUES (1,1,1262264305,2071469433,'','��: ��! 论�已��正常��.',1,1,'',0,1,0,0)
Error number: 1054
Error message: Unknown column 'poster_ip' in 'field list'
根据提示,去查了一下代码:
grep poster_ip * -r
class/post.php: $this->initVar('poster_ip', XOBJ_DTYPE_INT, 0);
class/post.php: $user_ok = ($user_ip == $this->getVar('poster_ip')) ? true : false;
class/post.php: 'poster_ip' => ($isadmin && $xoopsModuleConfig['show_ip']) ? long2ip($this->getVar('poster_ip')) : "",
include/module.v100.php: $result = $GLOBALS['xoopsDB']->queryF("ALTER TABLE ".$GLOBALS['xoopsDB']->prefix("bb_posts")." CHANGE `poster_ip` `poster_ip` INT(11) NOT NULL DEFAULT '0'");
include/module.php: $forumpost->setVar('poster_ip', newbb_getIP());
include/functions.welcome.inc.php: $post_obj->setVar('poster_ip', newbb_getIP());
moderate.php: $post_obj->setVar("poster_ip", newbb_getIP());
post.php: $post_obj->setVar('poster_ip', newbb_getIP());
sql/mysql.sql: `poster_ip` int(11) NOT NULL default '0',
sql/mysql.400.sql: CHANGE `poster_ip` `poster_ipd` varchar(15) NOT NULL default '0.0.0.0',
templates/newbb_thread.html: <{if $topic_post.poster_ip}>
templates/newbb_thread.html: IP: <a href="http://www.whois.sc/<{$topic_post.poster_ip}>" target="_blank"><{$topic_post.poster_ip}></a> |
templates/newbb_item.html:<{if $topic_post.poster_ip}>
templates/newbb_item.html:IP: <a href="http://www.whois.sc/<{$topic_post.poster_ip}>" target="_blank"><{$topic_post.poster_ip}></a>
viewpost.php: 'poster_ip' => ($isadmin && $xoopsModuleConfig['show_ip']) ? long2ip($post->getVar('poster_ip')) : "",
发现在sql/mysql.400.sql中改变了原来数据库的结构,将poster_ip修改为poster_ipd, 而在代码中提交时的字段却为poster_ip.
mysql.400.sql中改变数据库结构的代码在哪里?
$ grep "400.sql" * -r -B 3 -A3
include/module.php- }
include/module.php-
include/module.php- if ($oldversion < 400) {
include/module.php: $GLOBALS['xoopsDB']->queryFromFile(XOOPS_ROOT_PATH . "/modules/" . $module->getVar("dirname", "n") . "/sql/mysql.400.sql");
include/module.php- include dirname(__FILE__) . "/module.v400.php";
include/module.php- xoops_module_update_newbb_v400($module);
include/module.php- }
这段代码位于include/module.php的xoops_module_update_newbb函数调用中,就是说如果从4.00以前的版本升级上来之后,数据表bb_posts的结构会被修改,字段为poster_ip会被修改为poster_ipd, 从而导致无法正确执行insert语句,从而导致无法回复。
好多年不摸php了,如果分析错了,请指正。