Topic: google xml sitemap creator
this creates the xml google sitemap for submission to their sitemap submission service
http://www.google.com/webmasters/sitemaps/
it creates googlemap.xml for rewritten urls
and googlemap2.xml for non rewritten urls
it also creates txt files containing a list of the listing urls both rewritten and non rewritten forms named googlemap.txt and googlemap2.txt
the rewritten urls use the format of
siteid.html
instead of detail.php?siteid=
so detail.php?siteid=112
becomes 112.html
if you have support for apache rewrite
just add this to your .htaccess or php.ini
RewriteEngine on
#RewriteRule ^~(.*)$ /profile.php?profile=$1 [L]
RewriteRule ^([a-zA-Z0-9]*).html detail.php?siteid=$1copy and paste the script below to a new page named whatever you want, changing the settings to what maches yours, when ever this page is called it updates all the files or creates them if they dont exist, so setting up a cron job to update is a good idea....
<?
// site map creator for rewritten and non rewritten urls
// creates google compliant xml files for their sitemap service
// creates a txt list of all listing urls
// SETTINGS TO BE EDITED
$url = "http://www.yourdomain.com/path to/classifieds/" ; // url to directory must have trailing slash
$pageurl = "http://www.yourdomain.com/path to/classifieds/detail.php?siteid=" ; //url to listing no trailing slash
$changefreq = "daily" ; // either daily, weekly, or monthly
$priority = "1.0" ; // any number from 0.0 to 1.0
$hostname_sitemap = "localhost"; // mysql location
$database_sitemap = "***************"; // mysql database
$username_sitemap = "********"; // mysql user
$password_sitemap = "********"; // mysql password
// no more editing needed beyond here
$sitemap = mysql_pconnect($hostname_sitemap, $username_sitemap, $password_sitemap) or trigger_error(mysql_error(),E_USER_ERROR);
// REWRITTEN URLS GOOGLE XML SITE MAP
// first open let's open the sitemap xml and write the header info
$fp = fopen("googlemap.xml","w");
fwrite($fp, "n<?xml version="1.0" encoding="UTF-8"?>n");
fwrite($fp, "<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">n");
fclose($fp);
// okay know let's hook up with our base and slide our query in
mysql_select_db($database_sitemap, $sitemap);
$query_Recordset1 = "SELECT * FROM ad";
$Recordset1 = mysql_query($query_Recordset1, $sitemap) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
do {
//now time to spread the love on the page
$fp = fopen("googlemap.xml","a");
fwrite($fp, "n<url>n");
fwrite($fp, "<loc>" . $url . $row_Recordset1['siteid'] .".html</loc>n");
fwrite($fp, "<changefreq>". $changefreq . "</changefreq>n");
fwrite($fp, "<priority>". $priority ."</priority>n");
fwrite($fp, "</url>n");
fclose($fp);
// fancy stuff going on here
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
mysql_free_result($Recordset1);
// time to close up shop tabla rosa let's spark the jay
$fp = fopen("googlemap.xml","a");
fwrite($fp, "n</urlset>n");
fclose($fp);
echo 'rewritten url google map created <br>';
// END REWRITTEN URLS GOOGLE XML SITE MAP
// NON-REWRITTEN URLS GOOGLE XML SITE MAP
// first open let's open the sitemap xml and write the header info
$fp = fopen("googlemap2.xml","w");
fwrite($fp, "n<?xml version="1.0" encoding="UTF-8"?>n");
fwrite($fp, "<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">n");
fclose($fp);
// okay know let's hook up with our base and slide our query in
mysql_select_db($database_sitemap, $sitemap);
$query_Recordset1 = "SELECT * FROM ad";
$Recordset1 = mysql_query($query_Recordset1, $sitemap) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
do {
//now time to spread the love on the page
$fp = fopen("googlemap2.xml","a");
fwrite($fp, "n<url>n");
fwrite($fp, "<loc>" .$pageurl . $row_Recordset1['siteid'] ."</loc>n");
fwrite($fp, "<changefreq>". $changefreq . "</changefreq>n");
fwrite($fp, "<priority>". $priority ."</priority>n");
fwrite($fp, "</url>n");
fclose($fp);
// more fancyness
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
mysql_free_result($Recordset1);
// time to close up shop tabla rosa let's spark the jay
$fp = fopen("googlemap2.xml","a");
fwrite($fp, "n</urlset>n");
fclose($fp);
echo 'non rewritten url google map created <br>';
// END NON REWRITTEN URLS GOOGLE XML SITE MAP
// TEXT MAP REWRITTEN URLS
// first open let's open and clear the file
$fp = fopen("googlemap.txt","w");
fclose($fp);
// okay know let's hook up with our base and slide our query in
mysql_select_db($database_sitemap, $sitemap);
$query_Recordset1 = "SELECT * FROM ad";
$Recordset1 = mysql_query($query_Recordset1, $sitemap) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
// huh huh we are doing it
do {
//now time to spread the love on the page
$fp = fopen("googlemap.txt","a");
fwrite($fp, $url . $row_Recordset1['siteid'] .".htmln");
fclose($fp);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
mysql_free_result($Recordset1);
// time to close up shop tabla rosa let's spark the jay
echo 'rewritten url google map text created <br>';
// END TEXT MAP REWRITTEN URLS
// TEXT MAP NON REWRITTEN URLS
// first open let's open and clear the file
$fp = fopen("googlemap2.txt","w");
fclose($fp);
// okay know let's hook up with our base and slide our query in
mysql_select_db($database_sitemap, $sitemap);
$query_Recordset1 = "SELECT * FROM ad";
$Recordset1 = mysql_query($query_Recordset1, $sitemap) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
do {
//now time to spread the love on the page
$fp = fopen("googlemap2.txt","a");
fwrite($fp, $pageurl . $row_Recordset1['siteid'] ."n");
fclose($fp);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
mysql_free_result($Recordset1);
// time to close up shop tabla rosa let's spark the jay
echo 'non rewritten url google text map created <br>';
// END TEXT MAP NON REWRITTEN URLS
?>