访客端口主要用到 变量$_SERVER['REMOTE_PORT'] (用户连接到服务器时所使用的端口 ) 以下:访客端口开发基于 Discuz x2系统(请先在测试环境中进行,测试通过再上线。如根据下面教程出现问题,本人也将不承担任何责任) 根据需求主要显示的访客端口页面如图
上述两个访客端口显示位置 对应的文件space_profile.htm ,topicadmin_getip.htm 具体步骤: 建字段 1. 会员状态表common_member_status 添加两个字段:注册IP端口 字段,最后一次访问端口 字段 (regipport,lastipport),端口长度6个char就够了 默认为0 不能为空 2.帖子表 pre_forum_post 添加一个字段:发帖/回帖时的访客IP端口字段(useport) 修改对应文件代码 Discuz !X2需要修改的文件如下: class_member.php space_profile.htm topicadmin_getip.php topicadmin_getip.htm post_newthread.php post_newreply.php
文件不少,但是修改的东西很少的 class_member.php 233行左右 DB::insert('common_member_status', array( 'uid' => $uid, 'regip' => $_G['clientip'], 'lastip' => $_G['clientip'], 'lastvisit' => TIMESTAMP, 'lastactivity' => TIMESTAMP, 'lastpost' => 0, 'lastsendmail' => 0, /* jxr 20130425 lastipport regipport*/ 'regipport' => $_SERVER['REMOTE_PORT'], 'lastipport' => $_SERVER['REMOTE_PORT'] )); 308行左右 /* jxr 20130425 lastipport*/ DB::query("UPDATE ".DB::table('common_member_status')." SET lastip='".$_G['clientip']."', lastvisit='".time()."', lastactivity='".TIMESTAMP."',lastipport='".$_SERVER['REMOTE_PORT']."' WHERE uid='$_G[uid]'"); 1290行左右 $status_data = array( 'uid' => $uid, 'regip' => $_G['clientip'], 'lastip' => $_G['clientip'], 'lastvisit' => TIMESTAMP, 'lastactivity' => TIMESTAMP, 'lastpost' => 0, 'lastsendmail' => 0, /* jxr 20130425 lastipport regipport*/ 'regipport' => $_SERVER['REMOTE_PORT'], 'lastipport' => $_SERVER['REMOTE_PORT'], ); 以上黄色背景的都是添加的部分,这个文件添加好了之后修改 space_profile.htm 250行左右 <li><em>{lang register_ip}</em>$space[regip] <!--{if $space[regipport] != 0}-->undefinedspace[regipport]<!--{/if}--> - $space[regip_loc]</li> <li><em>{lang last_visit_ip}</em>$space[lastip] <!--{if $space[lastipport] != 0}-->undefinedspace[lastipport]<!--{/if}--> - $space[lastip_loc]</li> 上面第一张图 注册访客端口 和 最后访问访客端口已经完成 接下来要完成上面第二张图,即帖子内容也的IP访客端口的显示 post_newthread.php 993行左右 $pid = insertpost(array( 'fid' => $_G['fid'], 'tid' => $tid, 'first' => '1', 'author' => $_G['username'],
'authorid' => $_G['uid'], 'subject' => $subject, 'dateline' => $_G['timestamp'], 'message' => $message, 'useip' => $_G['clientip'], 'invisible' => $pinvisible, 'anonymous' => $isanonymous, 'usesig' => $usesig, 'htmlon' => $htmlon, 'bbcodeoff' => $bbcodeoff, 'smileyoff' => $smileyoff, 'parseurloff' => $parseurloff, 'attachment' => '0', 'tags' => $tagstr, 'replycredit' => 0, 'status' => (defined('IN_MOBILE') ? 8 : 0), /* jxr 20130425 useport */ 'useport' => $_SERVER['REMOTE_PORT'] )); post_newreply.php 693行左右 $pid = insertpost(array( 'fid' => $_G['fid'], 'tid' => $_G['tid'], 'first' => '0', 'author' => $_G['username'], 'authorid' => $_G['uid'], 'subject' => $subject, 'dateline' => $_G['timestamp'], 'message' => $message, 'useip' => $_G['clientip'], 'invisible' => $pinvisible, 'anonymous' => $isanonymous, 'usesig' => $usesig, 'htmlon' => $htmlon, 'bbcodeoff' => $bbcodeoff, 'smileyoff' => $smileyoff, 'parseurloff' => $parseurloff, 'attachment' => '0', 'status' => (defined('IN_MOBILE') ? 8 : 0), /* jxr 20130425 useport */ 'useport' => $_SERVER['REMOTE_PORT'], )); topicadmin_getip.php 39行左右 $member = DB::fetch_first("SELECT m.adminid, p.first, p.useip ,p.useport FROM ".DB::table($posttable)." p LEFT JOIN ".DB::table('common_member')." m ON m.uid=p.authorid
WHERE p.pid='$pid' AND p.tid='$_G[tid]'"); topicadmin_getip.htm 3行左右 - <b>$member[useip] <!--{if $member[useport] != 0}-->undefinedmember[useport]<!--{/if}--> </b> $member[iplocation]
复制代码
以上黄色的部分为添加或修改的部分,系统基于DISCUZ X2, 如果你用的是其他的系统的话 ,道理也是一样的 (你要对自己的系统数据库和代码结构要稍微有了解) 先建字段(添加这个字段的话,数据表数据量大的话,要花不少时间,最好空闲的时候再添加),然后找到并修改关联的文件,让前台的模板文件可以获取到对应的访客端口的字段 |