Antonio Grazioli Web Site
Web Technologies & more...

 

 

Main Menu
Home
News
Web Technologies
SQL Server
Portfolio
Downloads
Contact me
Search...

Google Sitemap for phpBB Forums with ASP code

I needed to create a simple Google Sitemap for a phpBB Forum hosted on a Windows-based domain.
So I had to use ASP code...

I started form this script and made my modifications as usual. The final sitemap will contain all the topics in your phpB Forum.

PLEASE NOTE that my modification doesn't take into account private or protected forums, it just browses all available forums. Also, no URL rewriting or fancy stuff...

Use the following code and save it as an.asp page. Google accepted it with no problem. 

 

'change this for your connection file
<!--#include file="MyConnections.asp" -->
<%
MAXURLS_PER_SITEMAP = 50000

'modify this to change website, baseurl and table
baseurl="http://www.yoursite.com/Forum/viewtopic.php?t="

strsql = "SELECT * FROM phpbb_topics"

'see http://www.time.gov/ for utcOffset
utcOffset=1
response.ContentType = "text/xml"
response.write "<?xml version='1.0' encoding='UTF-8'?>"
response.write "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>"

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open MM_conn_MySql_STRING

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn

Do while not rs.eof
    if URLS<MAXURLS_PER_SITEMAP then

'modify this to change database field
        id_page=(rs("topic_id"))
        filelmdate=date()
        priority=1

if not isdate(filelmdate) then filelmdate=now()
        filedate=iso8601date(filelmdate,utcOffset)

if priority="" or priority>1.0 then priority="1.0"
response.write "<url><loc>"&(baseurl&id_page)&"</loc><lastmod>"&filedate&"</lastmod>
<priority>"&priority&"</priority></url>"
        URLS=URLS+1
        Response.Flush
    rs.movenext
end if
Loop
response.write "</urlset>"
rs.Close

Set rs = Nothing

conn.Close

Set conn = Nothing

Function iso8601date(dLocal,utcOffset)
    Dim d
    ' convert local time into UTC
    d = DateAdd("H",-1 * utcOffset,dLocal)

' compose the date
    iso8601date = Year(d) & "-" & Right("0" & Month(d),2) & "-" & Right("0" & Day(d),2) & "T" & _
        Right("0" & Hour(d),2) & ":" & Right("0" & Minute(d),2) & ":" & Right("0" & Second(d),2) & "Z"

End Function

%>
 
< Prev   Next >