Tommy 碎碎念

Tommy Wu's blog

« 上一篇 | 下一篇 »

讓 PhpBB2 也用中文數字吧!
post by tommy @ 01 三月, 2007 16:02
同樣的方式, 我們也可以讓 phpBB 也使用中文數字的圖片.

首先, 利用前述的方式, 產生你的數字圖檔, 並選取一個背景圖檔. 在 include 的目錄下, 建立一個 chinese_img 的目錄, 把這些檔案放進去.

然後產生一個新的檔案 usercp_captcha_chinese.php, 放到 include, 內容如下:

<?php
 
if ( !defined('IN_PHPBB') )
{
die('Hacking attempt');
exit;
}
// Do we have an id? No, then just exit
if (empty($HTTP_GET_VARS['id']))
{
exit;
}
 
$confirm_id = htmlspecialchars($HTTP_GET_VARS['id']);
 
if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
{
$confirm_id = '';
}
 
$gd = true;
if(!extension_loaded("gd")){
//Gd isn't loaded
//Display error messages always, or not?
$gd = false;
}
if(!function_exists("gd_info") || !function_exists('imagettftext')){
//GD function, gd_info don't exists. GD isn't loaded correctly.
//Freetype function imagettftext doesn't exists. This is required by this mod.
$gd = false;
}
if($gd === false){
//GD not loaded, or one of the needed functions aren't there. Require usercp_confirm ;)
require($phpbb_root_path . 'includes/usercp_confirm.' . $phpEx);
die;
}
 
// Try and grab code for this id and session
$sql = 'SELECT code
FROM '
. CONFIRM_TABLE . "
WHERE session_id = '"
. $userdata['session_id'] . "'
AND confirm_id = '$confirm_id'"
;
$result = $db->sql_query($sql);
 
// If we have a row then grab data else create a new id
if ($row = $db->sql_fetchrow($result))
{
$db->sql_freeresult($result);
$code = $row['code'];
}
else
{
exit;
}
 
$len = strlen($code);
$im = ImageCreate(24 * $len, 24);
$background = ImageColorAllocate($im, 255, 255, 255);
 
$bg_file = $phpbb_root_path . 'includes/chinese_img/background.gif';
$im_bg = @ImageCreateFromGIF($bg_file);
if ($im_bg) {
list($width, $height, $type, $attr) = @GetImageSize($bg_file);
if (function_exists('ImageCopyReSampled'))
ImageCopyReSampled($im, $im_bg, 0, 0, 0, 0, 24 * $len, 24, $width, $height);
else
ImageCopyReSized($im, $im_bg, 0, 0, 0, 0, 24 * $len, 24, $width, $height);
ImageDestroy($im_bg);
}
 
for ($i = 0; $i < $len; $i++) {
$im_num = @ImageCreateFromPNG($phpbb_root_path . 'includes/chinese_img/'.$code[$i].'.png');
if ($im_num) {
ImageColorTransparent($im_num, ImageColorAt($im_num, 0, 0));
ImageCopy($im, $im_num, 24 * $i, 0, 0, 0, 24, 24);
ImageDestroy($im_num);
}
}
 
header("content-type:image/png");
header('Cache-control: no-cache, no-store');
 
ImagePNG($im);
ImageDestroy($im);
die;
 
?>

然後修改 include/usercp_register.php 的內容, 找到:

$code = dss_rand();

把下頭的 $code = substr(... 這行改成:

$code = substr(base_convert($code, 16, 10), 2, 6);

然後修改 profile.php 的內容, 找到:

include($phpbb_root_path . 'includes/usercp_confirm.'.$phpEx);

把這行改成:

include($phpbb_root_path . 'includes/usercp_captcha_chinese.'.$phpEx);

經過這樣子的修改, 應該就可以在註冊時看到那個圖片變成中文的數字了. 

那個新增的檔案與圖型檔, 也可以由這兒抓取: http://www.teatime.com.tw/~tommy/files/phpbb2_captcha_chinese.tgz  

把這個檔案在 include 目錄中解開就可以了.

Del.icio.us Furl HEMiDEMi Technorati MyShare
commons icon [1] Re:讓 PhpBB2 也用中文數字吧! [ 回覆 ]

您好
在讀過此2篇文章後便動手執行修改
不料卻無法正確執行
想在此與您請教
1.在前篇中第一段程式碼應儲存在何處,檔名應為何?
2.在前篇中所提到的"pluginauthimage.class.php"不知應在哪個資料夾內?

commons icon [2] Re:讓 PhpBB2 也用中文數字吧! [ 回覆 ]

那個檔案是 lifetype 的 authimage plugin, 裝了就有了.

commons icon [3] Re:讓 PhpBB2 也用中文數字吧! [ 回覆 ]

請問在PHPBB3裡該如何使用呢?

commons icon [4] Re:讓 PhpBB2 也用中文數字吧! [ 回覆 ]

沒有改給 phpbb3 用的版本, 如果需要請自己改.
如果只是要擋廣告, 用這一篇的方法應該就有一樣的效果.
http://blog.teatime.com.tw/1/post/411

迴響
暱稱:
標題:
個人網頁:
電子郵件:
authimage

迴響

  

Bad Behavior 已經阻擋了 85 個過去 7 天試圖闖關的垃圾迴響與引用。
Power by LifeType. Template design by JamesHuang. Valid XHTML and CSS