PDA

View Full Version : Cần 1 scrip làm Sitemap với số lượng Link lớn



yodownload.net
20-02-2010, 15:52
Chả là website mình chạy bằng 2 mã nguồn là Joomla và Vbulletin ( có lic ), nhưng dùng 2 domain nên đối với vbulletin dùng Vbsitemap của VBSEO thì submit vào Google Mastertool bị lỗi.

anh em nào biết 1 script tạo Sitemap cập nhật Auto hỗ trợ Unlimit link thì chỉ mình với nhé !

Leinside
20-02-2010, 17:54
Có lỗi là do config, bồ thử nói qua về nỗi báo tại google webmastertools lên đây - chụp full hình config vbseo sitemap tại admincp nữa.

boy271206
20-02-2010, 17:56
lỗi do config thôi cậu ah

shareinformation
20-02-2010, 18:01
save code sau thành file sitemap.php, lưu vào thư mục của web bạn (nơi có file index.php, nói chung là nó nằm ngay tại thư mục của forum), tạo 3 file topic.xml, forum.xml, user.xml và CMOD nó là 777, chạy file sitemap.php từ web bạn là xong :)
Xong, và chỉ cần chạy file php này, nó sẽ truy cập vào database và tạo ra link site map cho. Giờ chỉ việc submit file map.txt cho bot của google là xong
Có thể ứng dụng dùng cho tất cả những trang liên quan đến php + CSDL sql. Bạn chỉ cần sửa lại đường dẫn, tên table phù hợp là được.

Code này mình viết lâu rồi, nhiều web khác cũng dùng, rồi sửa code tùm lum, nhiều người lại "không tin" là code của mình. :(
Danh sách vài link mình Google ra là "lấy" của mình :D

http://10nit.com/index.php?showtopic=3776&mode=threaded&pid=21361
http://www.ddth.com/showthread.php?t=175575
http://freecodevn.com/for@um/showthread.php?t=48930
http://www.vietvbb.vn/up/showthread.php?t=9127
http://ipbviet.com/index.php?/topic/39-t%E1%BA%A1o-sitemap-cho-ipb/
http://itprovn.net/itvietnam/index.php?showtopic=3776
http://traitimyenbai.net/forum/viewthread.php?tid=27400
http://traitimyenbai.net/forum/viewthread.php?tid=30352

Giải thích chút xíu về đoạn code:
Nó sẽ lấy thông tin config từ file config.php
Sau đó kết nối vào SQL
Lấy ID những topic và forum, bài viết
Và chỉ việc Echo ra file sitemap, như vậy là sitemap tạo ra sẽ "chính xác" và "không xót một xu", mà lại đúng chuẩn cho các bot :)



<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<?php
// thông tin file config và sql
include('config.php');
$sql_table_topics = "".$table_prefix."topics";
$sql_table_forums = "".$table_prefix."forums";
$sql_table_users = "".$table_prefix."users";
$sql_table_config = "".$table_prefix."config";

//kết nối SQL
$conn = mysql_connect($dbhost, $dbuser, $dbpasswd);
if ( !$conn ) {
//Không kết nối được, thoát ra và báo lỗi
die("không nết nối được vào MySQL server: ".mysql_error($conn));
} //end if
//chọn CSDL để làm việc
mysql_select_db($dbname, $conn)
or die("Không thể chọn được CSDL: ".mysql_error($conn));

//Kiểu truy cập server_protocol
$sql_server_protocol = "SELECT * FROM $sql_table_config WHERE `config_name` LIKE 'server_protocol'";
$result_server_protocol = mysql_query($sql_server_protocol, $conn);
if ( !$result_server_protocol )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_server_protocol = mysql_fetch_assoc($result_server_protocol) ) {$server_protocol = "".$row_server_protocol[config_value]."";} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_server_protocol);

//Đường dẫn diễn đàn
$sql_server_name = "SELECT * FROM $sql_table_config WHERE `config_name` LIKE 'server_name'";
$result_server_name = mysql_query($sql_server_name, $conn);
if ( !$result_server_name )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_server_name = mysql_fetch_assoc($result_server_name) ) {$server_name = "".$row_server_name[config_value]."";} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_server_name);

//Đường dẫn thư mục diễn đàn
$sql_script_path = "SELECT * FROM $sql_table_config WHERE `config_name` LIKE 'script_path'";
$result_script_path = mysql_query($sql_script_path, $conn);
if ( !$result_script_path )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_script_path = mysql_fetch_assoc($result_script_path) ) {$script_path = "".$row_script_path[config_value]."";} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_script_path);

$linkwebsite = "$server_protocol$server_name$script_path";

// Thông tin file xml, không edit mục này
$header_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<rss version=\"2.0\">\n<channel>\n<title>Sitemap VBB ".$linkwebsite."</title>\n<description>Powered by Nguyễn Thanh Phong http://www.goctamhon.com</description>\n<link>".$linkwebsite."</link>\n<ttl>1</ttl>\n";
$footer_xml = "<item><title>Góc tâm hồn, nghệ thuật sống, bài học cuộc sống, hạt giống tâm hồn, học làm người</title><link>http://www.goctamhon.com</link></item>\n</channel>\n</rss>";
$file_topic = fopen("topic.xml", "w+");
fwrite($file_topic, $header_xml);
$file_forum = fopen("forum.xml", "w+");
fwrite($file_forum, $header_xml);
$file_user = fopen("user.xml", "w+");
fwrite($file_user, $header_xml);

// Chọn sql topic
$sql_topic = "SELECT * FROM $sql_table_topics";
$result_topic = mysql_query($sql_topic, $conn);
if ( !$result_topic )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_topic = mysql_fetch_assoc($result_topic) ) {
fwrite($file_topic, "<item><title>".$row_topic['topic_title']."</title><link>".$linkwebsite."/viewtopic.php?t=".$row_topic['topic_id']."</link></item>\n");
} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_topic);

// Chọn sql forum
$sql_forum = "SELECT * FROM $sql_table_forums";
$result_forum = mysql_query($sql_forum, $conn);
if ( !$result_forum )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_forum = mysql_fetch_assoc($result_forum) ) {
fwrite($file_forum, "<item><title>".$row_forum['forum_name']."</title><link>".$linkwebsite."/viewforum.php?f=".$row_forum['forum_id']."</link></item>\n");
} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_forum);

// Chọn sql user
$sql_user = "SELECT * FROM $sql_table_users";
$result_user = mysql_query($sql_user, $conn);
if ( !$result_user )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_user = mysql_fetch_assoc($result_user) ) {
fwrite($file_user, "<item><title>".$row_user['username']."</title><link>".$linkwebsite."/memberlist.php?u=".$row_user['user_id']."</link></item>\n");
} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_user);

// Kết thúc không edit mục này
fwrite($file_topic, $footer_xml);
fclose($file_topic);
fwrite($file_forum, $footer_xml);
fclose($file_forum);
fwrite($file_user, $footer_xml);
fclose($file_user);
//đóng kết nối
mysql_close($conn);
echo "Đã tạo xong sitemap !! Bạn hãy vào:<br><a href=\"http://www.google.com/webmasters/sitemaps\" target=\"_blank\">Google Sitemaps</a><br><a href=\"https://siteexplorer.search.yahoo.com/submit\" target=\"_blank\">Yahoo Site Explorer</a><br><a href=\"http://search.msn.com/docs/submit.aspx\" target=\"_blank\">Live Search</a><br>để submit sitemap của bạn cho họ với các file xml sau:<br><a href=topic.xml target=\"_blank\">".$linkwebsite."/topic.xml</a><br><a href=forum.xml target=\"_blank\">".$linkwebsite."/forum.xml</a><br><a href=user.xml target=\"_blank\">".$linkwebsite."/user.xml</a><br><center>Powered by Nguyễn Thanh Phong <a href=\"http://www.goctamhon.com\" target=\"_blank\">http://www.goctamhon.com</a></center>";
?>

yodownload.net
20-02-2010, 20:52
Ồ, rất cám ơn bạn shareinformation, với cách chạy file sitemap.php thì chỉ cần tạo 1 cái cron cho nó auto run là được, nhưng mình thắc mắc là số lượng link được tạo có bị giới hạn cho mỗi file ko vì số lượng link của mình rất nhiều ?

[=========> Bổ sung bài viết <=========]


lỗi do config thôi cậu ah
Biết là do lỗi config, biết chô để sửa luôn, nhưng ko sửa được vì mình chạy 2 domain nên phần URL link phải để là "/forum" cho các link khác hiểu nên khi tạo sitemap thì mọi link đều bị "cụt" đầu và đều là "/forum/forumdisplay..." ko thôi :D

Xài 1 domain thì config lại là ok thôi.

lee_huynh306
20-02-2010, 21:05
Google limit ở 50k links, làm unlimited sao được.

yodownload.net
20-02-2010, 21:10
Google limit ở 50k links, làm unlimited sao được.
Chính xác, Google cho 50K / 1file sitemap, nhưng nếu dùng VbSitemap thì nó sẽ tự động chia nhỏ ra nếu quá 50K link trong 1 file. :( tiếc là mình không thể dùng vbsitemap, nên mới nhờ anh em giúp 1 script khác, có cùng chức năng ?

shareinformation
21-02-2010, 09:11
Google gới hạn 50.000 link.
Zậy thì chỉnh lại cái code sitemap kia của mình, cho nó kiểm tra số lượng, chia nhỏ file sitemap ra từng phần, mỗi phần 50.000 link :D

rootvnnet
21-02-2010, 09:24
Google gới hạn 50.000 link.
Zậy thì chỉnh lại cái code sitemap kia của mình, cho nó kiểm tra số lượng, chia nhỏ file sitemap ra từng phần, mỗi phần 50.000 link :D

cậu edit sẵn giúp lun đi :D

shareinformation
21-02-2010, 10:53
Mình không rành cái vụ chia trang này.

Henry.Nguyen
21-02-2010, 15:27
Sitemap mà nhiều link quá liệu có ảnh hưởng tới SEO không nhỉ?

www.SimDep.us
21-02-2010, 16:13
save code sau thành file sitemap.php, lưu vào thư mục của web bạn (nơi có file index.php, nói chung là nó nằm ngay tại thư mục của forum), tạo 3 file topic.xml, forum.xml, user.xml và CMOD nó là 777, chạy file sitemap.php từ web bạn là xong :)
Xong, và chỉ cần chạy file php này, nó sẽ truy cập vào database và tạo ra link site map cho. Giờ chỉ việc submit file map.txt cho bot của google là xong
Có thể ứng dụng dùng cho tất cả những trang liên quan đến php + CSDL sql. Bạn chỉ cần sửa lại đường dẫn, tên table phù hợp là được.

Code này mình viết lâu rồi, nhiều web khác cũng dùng, rồi sửa code tùm lum, nhiều người lại "không tin" là code của mình. :(
Danh sách vài link mình Google ra là "lấy" của mình :D


Giải thích chút xíu về đoạn code:
Nó sẽ lấy thông tin config từ file config.php
Sau đó kết nối vào SQL
Lấy ID những topic và forum, bài viết
Và chỉ việc Echo ra file sitemap, như vậy là sitemap tạo ra sẽ "chính xác" và "không xót một xu", mà lại đúng chuẩn cho các bot :)



<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<?php
// thông tin file config và sql
include('config.php');
$sql_table_topics = "".$table_prefix."topics";
$sql_table_forums = "".$table_prefix."forums";
$sql_table_users = "".$table_prefix."users";
$sql_table_config = "".$table_prefix."config";

//kết nối SQL
$conn = mysql_connect($dbhost, $dbuser, $dbpasswd);
if ( !$conn ) {
//Không kết nối được, thoát ra và báo lỗi
die("không nết nối được vào MySQL server: ".mysql_error($conn));
} //end if
//chọn CSDL để làm việc
mysql_select_db($dbname, $conn)
or die("Không thể chọn được CSDL: ".mysql_error($conn));

//Kiểu truy cập server_protocol
$sql_server_protocol = "SELECT * FROM $sql_table_config WHERE `config_name` LIKE 'server_protocol'";
$result_server_protocol = mysql_query($sql_server_protocol, $conn);
if ( !$result_server_protocol )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_server_protocol = mysql_fetch_assoc($result_server_protocol) ) {$server_protocol = "".$row_server_protocol[config_value]."";} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_server_protocol);

//Đường dẫn diễn đàn
$sql_server_name = "SELECT * FROM $sql_table_config WHERE `config_name` LIKE 'server_name'";
$result_server_name = mysql_query($sql_server_name, $conn);
if ( !$result_server_name )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_server_name = mysql_fetch_assoc($result_server_name) ) {$server_name = "".$row_server_name[config_value]."";} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_server_name);

//Đường dẫn thư mục diễn đàn
$sql_script_path = "SELECT * FROM $sql_table_config WHERE `config_name` LIKE 'script_path'";
$result_script_path = mysql_query($sql_script_path, $conn);
if ( !$result_script_path )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_script_path = mysql_fetch_assoc($result_script_path) ) {$script_path = "".$row_script_path[config_value]."";} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_script_path);

$linkwebsite = "$server_protocol$server_name$script_path";

// Thông tin file xml, không edit mục này
$header_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<rss version=\"2.0\">\n<channel>\n<title>Sitemap VBB ".$linkwebsite."</title>\n<description>Powered by Nguyễn Thanh Phong http://www.goctamhon.com</description>\n<link>".$linkwebsite."</link>\n<ttl>1</ttl>\n";
$footer_xml = "<item><title>Góc tâm hồn, nghệ thuật sống, bài học cuộc sống, hạt giống tâm hồn, học làm người</title><link>http://www.goctamhon.com</link></item>\n</channel>\n</rss>";
$file_topic = fopen("topic.xml", "w+");
fwrite($file_topic, $header_xml);
$file_forum = fopen("forum.xml", "w+");
fwrite($file_forum, $header_xml);
$file_user = fopen("user.xml", "w+");
fwrite($file_user, $header_xml);

// Chọn sql topic
$sql_topic = "SELECT * FROM $sql_table_topics";
$result_topic = mysql_query($sql_topic, $conn);
if ( !$result_topic )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_topic = mysql_fetch_assoc($result_topic) ) {
fwrite($file_topic, "<item><title>".$row_topic['topic_title']."</title><link>".$linkwebsite."/viewtopic.php?t=".$row_topic['topic_id']."</link></item>\n");
} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_topic);

// Chọn sql forum
$sql_forum = "SELECT * FROM $sql_table_forums";
$result_forum = mysql_query($sql_forum, $conn);
if ( !$result_forum )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_forum = mysql_fetch_assoc($result_forum) ) {
fwrite($file_forum, "<item><title>".$row_forum['forum_name']."</title><link>".$linkwebsite."/viewforum.php?f=".$row_forum['forum_id']."</link></item>\n");
} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_forum);

// Chọn sql user
$sql_user = "SELECT * FROM $sql_table_users";
$result_user = mysql_query($sql_user, $conn);
if ( !$result_user )
die("Không thể thực hiện được câu lệnh SQL: ".mysql_error($conn));
while ( $row_user = mysql_fetch_assoc($result_user) ) {
fwrite($file_user, "<item><title>".$row_user['username']."</title><link>".$linkwebsite."/memberlist.php?u=".$row_user['user_id']."</link></item>\n");
} //end while
//nên luôn giải phóng bộ nhớ sau khi lấy hết các row trả về từ câu lệnh SELECT
mysql_free_result($result_user);

// Kết thúc không edit mục này
fwrite($file_topic, $footer_xml);
fclose($file_topic);
fwrite($file_forum, $footer_xml);
fclose($file_forum);
fwrite($file_user, $footer_xml);
fclose($file_user);
//đóng kết nối
mysql_close($conn);
echo "Đã tạo xong sitemap !! Bạn hãy vào:<br><a href=\"http://www.google.com/webmasters/sitemaps\" target=\"_blank\">Google Sitemaps</a><br><a href=\"https://siteexplorer.search.yahoo.com/submit\" target=\"_blank\">Yahoo Site Explorer</a><br><a href=\"http://search.msn.com/docs/submit.aspx\" target=\"_blank\">Live Search</a><br>để submit sitemap của bạn cho họ với các file xml sau:<br><a href=topic.xml target=\"_blank\">".$linkwebsite."/topic.xml</a><br><a href=forum.xml target=\"_blank\">".$linkwebsite."/forum.xml</a><br><a href=user.xml target=\"_blank\">".$linkwebsite."/user.xml</a><br><center>Powered by Nguyễn Thanh Phong <a href=\"http://www.goctamhon.com\" target=\"_blank\">http://www.goctamhon.com</a></center>";
?>


Bác có thể hướng dẫn dùm chi tiết, cụ thể hơn nữa được không bác? Trên nay không phải a,e nào cũng được học IT bài bản đâu,hic!
Thank bác nhiều nhiều nhé!

1n1
21-02-2010, 16:14
Bác config file bị lỗi nên anh google mới không nhận đó chứ ;)

shareinformation
21-02-2010, 16:27
Bạn đang dùng Vbb bản mấy?
Để mình cài tại localhost Test thử rồi "báo cáo" lại cho.

boy271206
21-02-2010, 18:16
Ồ, rất cám ơn bạn shareinformation, với cách chạy file sitemap.php thì chỉ cần tạo 1 cái cron cho nó auto run là được, nhưng mình thắc mắc là số lượng link được tạo có bị giới hạn cho mỗi file ko vì số lượng link của mình rất nhiều ?

[=========> Bổ sung bài viết <=========]


Biết là do lỗi config, biết chô để sửa luôn, nhưng ko sửa được vì mình chạy 2 domain nên phần URL link phải để là "/forum" cho các link khác hiểu nên khi tạo sitemap thì mọi link đều bị "cụt" đầu và đều là "/forum/forumdisplay..." ko thôi :D

Xài 1 domain thì config lại là ok thôi.

vẫn là lỗi do config, đừng nghĩ là chỉ site cậu chạy 2 domain.

yodownload.net
21-02-2010, 22:23
Bạn đang dùng Vbb bản mấy?
Để mình cài tại localhost Test thử rồi "báo cáo" lại cho.
3.8.4 ( có lic ), cậu test thử nhé, mình cũng tìm dc vài script trên Internet nhưng chưa thử.


vẫn là lỗi do config, đừng nghĩ là chỉ site cậu chạy 2 domain.
Vậy config chỗ nào :D nói sai config thì ai chả nói dc :D. Mọi file sitemap của mình đều có các url dạng "/forum/...." chứ không đầy đủ domain cụ thể. Site map do vbsitemap tạo ra thì ghi rõ cụ thê domain mới submit thành công, còn mình để trống tuy chạy dc website nhưng lại báo lỗi sitemap, bó tay.

boy271206
22-02-2010, 00:27
3.8.4 ( có lic ), cậu test thử nhé, mình cũng tìm dc vài script trên Internet nhưng chưa thử.


Vậy config chỗ nào :D nói sai config thì ai chả nói dc :D. Mọi file sitemap của mình đều có các url dạng "/forum/...." chứ không đầy đủ domain cụ thể. Site map do vbsitemap tạo ra thì ghi rõ cụ thê domain mới submit thành công, còn mình để trống tuy chạy dc website nhưng lại báo lỗi sitemap, bó tay.

bác là webmaster mà ko rõ vụ này àh :blink:, đưa cái admincp thì tui config hộ cho :D

shareinformation
22-02-2010, 13:05
3.8.4 ( có lic ), cậu test thử nhé, mình cũng tìm dc vài script trên Internet nhưng chưa thử.

Híc, cái Vbb 3.8.4 có nhiều thay đổi so với bản Vbb cũ lúc mình viết cái code kia.
Bây giờ ngồi "mò" lại hơi mệt :emlaugh:

Lại lười :)

yodownload.net
22-02-2010, 15:33
Mình vừa kiếm được script này, có thấy ghi chức năng là "tự động chia nhỏ file nếu quá giới hạn 50K link trong file Sitemap" đó là : XML Sitemap Generator 2.9 - 3.0 ". Đây là script có tính phí , trang chủ tại đây : http://www.xml-sitemaps.com/

anh em có ai xài nó ko ?

Planer
08-04-2010, 10:59
Yes http://www.xml-sitemaps.com is best. Nhưng bây giờ liệu có cần thiết phải submit sitemap không? Để google index và crawl thì ko cần submit sitemap, submit sitemap mà google ko vào crawl thường xuyên thì để làm gì?