Charles Ma'nın cevap ekleme. Eğer aynı anda yazıyor olabilir eğer () sitemapper.php
adlı bir dosyada bu kaydedebilir ve bir GET sorgu ile bu dosyayı diyoruz, ben size daha fazla güvenlik eklemek için tavsiye ederiz, ancak, ve akın edebilir.
Eğer SimpleXMLParser yok PHP4 kullanıyorsanız bu kullanmak için başka bir nedeni olacaktır.
<?php
/*--------------------------------------------------------
==================
sitemapper.php 1.0
==================
Pass me a path to a page, and I will add it to your XML sitemap.
Paths are passed from root, as
www.example.com/sitemapper.php?path=/test/index.html
for a page at http://www.example.com/test/index.html
This script is faster than parsing XML, for large sitemaps.
--------------------------------------------------------*/
if (isset($_GET[path])) {
// Get the path to the new page to add to our sitemap.
$fname = urldecode($_GET[path]);
// Real path to files is different on some hosts.
$current_path = realpath(dirname(__FILE__));
if (!is_file("./sitemap.xml")){
$xml = '';
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"."\n";
$xml .= "<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"."\n";
$xml .= "</urlset>"."\n";
$sitemap = fopen("./sitemap.xml", "x");
fwrite($sitemap, $xml);
fclose($sitemap);
}
// Write sitemap.xml entry for current file
// This is a very old-school 'C' style of doing it.
// The modern way would be to open the file in an XML parser,
// add the elements you want, serialise it to a new file
// and swap them over (so that nothing reads the XML in
// the middle of you writing it)
//
// However I expect this XML file to become *huge* shortly
// So I am avoiding use of the PHP XML Parser.
$date = date('Y-m-dTH:i:sP', time()); //Date in w3c format for XML sitemaps
$xml = '';
$xml .= "<url>"."\n";
$xml .= " <loc>http://". $_SERVER["HTTP_HOST"] . $fname . "</loc>"."\n";
$xml .= " <lastmod>" . $date . "</lastmod>"."\n";
$xml .= " <priority>0.50</priority>"."\n";
$xml .= " <changefreq>never</changefreq>"."\n";
$xml .= "</url>"."\n";
if ($sitemap = @fopen("./sitemap.xml", "r+"))
{
// seek to the end of the file, then iterate backwards one line.
// read the last line and store it temporarily. overwrite the
// last line with what you want to insert, then append the
// temporary line you stored previously.
$offset = filesize("./sitemap.xml") - 1;
fseek($sitemap, ($offset - 1)); //seek to before the last character in the file
while( (($char = fgetc($sitemap)) !== "\n") && ($offset > -2000) && ($offset < 2000)) {
// Go backwards, trying to find a line-break.
// The offset range is just a sanity check if something goes wrong.
$offset = $offset - 1;
fseek($sitemap, $offset);
}
$offset = $offset + 1; // Come to the beginning of the next line
fseek($sitemap, $offset);
$lastline = fgets($sitemap); // Copy the next line into a variable
fseek($sitemap, $offset); //go back to where the last line began
fwrite($sitemap, $xml); // add the current entry
fwrite($sitemap, $lastline); // add the </urlset> line back.
fclose($sitemap);
}
}
?>