Google sitemap PHP script
This is probably the simplest PHP script for creating Google sitemaps. Of course you should make some tweaks to make it run. First, change the username name and passoword for the MySQL DB. If you use a hosting company like godaddy, for example, you will have to change localhost also. Something like pXXmysqlYY.secureserver.net.
Second change concerns URLs, which is ih this type http://yoursite.com/url.php?id=XYZ.
If you still do not understand what to do, you will have to attend some progamming lessons.
And now, the script:
<?
// Connecting, selecting database
$link = mysql_connect(’localhost’, ‘db_username’, ‘db_pass’)
//db_username is the database username; db_pass is the database password
or die(’Could not connect: ‘ . mysql_error());
mysql_select_db(’data_base_name’) or die(’Could not select database’);
//data_base_name is the DB you connect to
// Performing SQL query
$query = ‘SELECT item_id FROM db_table_name WHERE some_condition=1′;
$result = mysql_query($query) or die(’Query failed: ‘ . mysql_error());
// Printing results in HTML
header (”Content-type: application/xml”);
echo “<?xml version=\”1.0\” encoding=\”UTF-8\”?>
<urlset xmlns=\”http://www.google.com/schemas/sitemap/0.84\”>\n”;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
foreach ($line as $col_value)
{
echo “<url>\n”;
echo “<loc>http://yoursite.com/url.php?id=$col_value</loc>\n”;
echo “</url>”;
}
}
echo “</urlset>\n”;
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
Good luck and high SERPs!
1 Comment
Enter this code
Yahoo sitemap PHP script
Although Yahoo is used as search engine much less than Google, it should not be omitted. Unlike the Google sitemap, where we created xml file, in this case we create a simple text file with list of all indexed-to-be URLs. (This file could be used inst…
Trackback :: February 26, 2008 @ 17:34 am