Mysql
 SQL >> Database >  >> RDS >> Mysql

Generare una sitemap con PHP e MySQL

La uso sul mio sito: funziona bene e puoi puntare gli strumenti per i webmaster di Google a this_file.php e funziona e basta:

<?php header("Content-type: text/xml"); echo'<?xml version=\'1.0\' encoding=\'UTF-8\'?>'; echo' <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.sitemaps.org/schemas/sitemap/0.9 https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; include '../include.php'; $sql = mysql_query("select blah from bleh"); while ($string = mysql_fetch_array($sql)){?> <url> <loc>https://www.domain.com/dir/<?echo $string['value'];?>/index.php</loc> <changefreq>weekly</changefreq> </url> <?php } ?> </urlset> 

Lo script imposta un content type XML, scorre le tue righe ed emette una voce <url> per ciascuna. Per un codice moderno, passa a mysqli o PDO ed effettua l'escape dei valori che inserisci nell'XML per mantenere l'output valido.