I have a PHP script to generate a sitemap: http://w3db.org/sitemapx.php
It's job is to make the sitemap1.xml file in the root directory, but it just shows the number of urls added.
It does not give an error. The script is OK but there is something wrong with permissions. I tried it using 777 but it is still not able to create the sitemap1.xml file in root directory.
sitemapx.php:
<?php
global $handle, $counter, $file_number, $filename ,$countx;
$counter = 0;
$countx = 0;
$file_number = 1;
include('config.php');
$con = mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$database", $con);
$result = mysql_query("SELECT * FROM table_name");
while($row = mysql_fetch_array($result)) {
$domx = $row["domain"];
$url = "http://www.w3db.org/www.".$domx."";
write_xml($url);
$countx++;
}
fwrite($handle,"</urlset>\n");
echo "Url to Sitemap Added : ".$countx;
function write_xml($url,$priority = 0.7) {
global $handle, $counter, $file_number, $filename;
if ($counter >= 50000) {
$file_number++;
$counter = 0;
fwrite($handle,"</urlset>\n");
fclose($handle);
}
if ($counter == 0) {
$filename = "sitemap" . $file_number . ".xml";
$handle = fopen($filename,"a");
fwrite($handle,'<?xml version="1.0" encoding="UTF-8"?>' . "\n");
fwrite($handle,'<urlset xmlns="http://www.google.com/schemas/sitemap/0.9">'."\n");
}
if ($url != "" && $url != "END") {
fwrite($handle,"\t <url>\n");
fwrite($handle,"\t\t<loc>$url</loc>\n");
fwrite($handle,"\t\t<priority>$priority</priority>\n");
fwrite($handle,"\t</url>\n");
}
if ($url == "") {
fwrite($handle,"</urlset>\n");
fclose($handle);
}
$counter++;
}
?>