PHP中BB生成sitemap地圖文件的方法
本文介紹下,在PHPBB論壇中生成sitemap地圖文件的實現代碼,感興趣的朋友參考學習下。
將以下PHP文件放到網站的根目錄。
加入此sitemap的前提:
必須將PHPBB論壇的默認URL規格改成以下文件裏生成的'格式。
具體方法,請參考:
注意:
紅色部分的代碼,修改成自己網站對應的內容:
複製代碼 代碼示例:
<?php
// By: Arlinger On 2012-6-4
//
// CUSTOM INSTALLATION VARIABLES:
$subdomain='www.';
$domain=' '; //這裏要改成你的網站名
$folder='/forum/'; //這裏要改成你把博客所在的文件夾的名字
$urls=50000;
// Change Nothing Below Here:
$domainpath='http://'.$subdomain.$domain.$folder;
// Connect
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'config.' . $phpEx);
include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
$db = new $sql_db();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
// Gzip compression
if (@extension_loaded('zlib') && !headers_sent())
{
ob_start('ob_gzhandler');
}
// Send Header
header("Content-Type: text/xml;charset=iso-8859-1");
// Send initial Data
echo '<?xml version="1.0" encoding="UTF-8"?>'."n";
echo '<urlset xmlns="">'."n";
// Send Index
$current_time=time();
echo '<url>
<loc>'.$domainpath.'</loc>
<lastmod>'("Y-m-dTH:i:sP",$current_time).'</lastmod>
</url>';
$urls=$urls-1;
// Send Forums
$sql = 'SELECT forum_id, forum_last_post_time FROM '.$table_prefix.'forums WHERE enable_indexing=1 LIMIT '.$urls;
$result = $db->sql_query($sql);
while ($data=$db->sql_fetchrow($result)) {
// Fix for parents forums showing 1969
if ($data['forum_last_post_time'] == 0) {
$data['forum_last_post_time']=$current_time;}
echo '<url>
<loc>'.$domainpath.'viewforum-'.$data['forum_id'].''.'</loc>
<lastmod>'("Y-m-dTH:i:sP",$data['forum_last_post_time']).'</lastmod>
</url>';
$urls=$urls-1;
}
$db->sql_freeresult($result);
// Send Topics
$sql = 'SELECT * FROM '.$table_prefix.'topics as t, '.$table_prefix.'forums as f WHERE c_approved=1 AND m_id=m_id AND le_indexing=1 ORDER BY c_id DESC LIMIT '.$urls;
$result = $db->sql_query($sql);
while ($data=$db->sql_fetchrow($result)) {
echo '<url>
<loc>'.$domainpath.'viewtopic-'.$data['topic_id'].''.'</loc>
<lastmod>'("Y-m-dTH:i:sP",$data['topic_last_post_time']).'</lastmod>
</url>';
}
$db->sql_freeresult($result);
// Send Closing Tags
echo ' </urlset>';
?>
-
php是什麼大綱
導讀:時至今日,仍有無以數計的童鞋出於各種渠道瞭解仍要來學習php,那麼對於新手來説,對php有一個清晰的認知則是很有必要的。Php是什麼?PHP是一種創建動態交互性站點的強有力的服務器端腳本語言。PHP是免費的,並且使用非常廣泛。同時,對於像微軟ASP這樣的競爭者來説,P...
-
php修改上傳文件大小限制實例詳解
php在默認情況下,只允許上傳一定大小的文件,當上傳文件大小超過這個值時,將會出錯。本文章將向大家講解中如何修改上傳文件大小限制。需要修改的設置有三個地方,請看下文:1、修改max_execution_time在php中,默認的頁面最久執行時間為30秒,超過30秒,該腳本就停止執行....
-
PHP正則匹配中文字母數字正則的表達式
PHP語言是一門實用性很強的語言,下面小編為大家帶來了關於PHP正則匹配中文字母數字正則的'表達式,歡迎大家閲讀!PHP正則匹配中文字母數字正則的表達式代碼如下if(preg_match("/^d*$/","4312")){echo"全數字";}if(preg_match("/^[a-z]*$/i","fdsFDfd")){echo"全...
-
PHP中多態如何實現
PHP是一種HTML內嵌式的,用來製作動態網頁的服務器端的腳本語言。以下是本站小編整理的PHP中多態如何實現的內容,歡迎學習!1PHP語言介紹PHP是一種HTML內嵌式的,用來製作動態網頁的服務器端的腳本語言。其特點是:開發週期短,穩定安全,簡單易學,免費開源,良好的跨平台特性...