Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Adding to Charles Ma's answer. You can save this in a file called <code>sitemapper.php</code>, and call this file with a GET query, although I would advise you to add more security, and flock() if you might have concurrent writes.</p> <p>Another reason to use this would be if you are using PHP4 which doesn't have the SimpleXMLParser.</p> <pre><code>&lt;?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 = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"."\n"; $xml .= "&lt;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\"&gt;"."\n"; $xml .= "&lt;/urlset&gt;"."\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 .= "&lt;url&gt;"."\n"; $xml .= " &lt;loc&gt;http://". $_SERVER["HTTP_HOST"] . $fname . "&lt;/loc&gt;"."\n"; $xml .= " &lt;lastmod&gt;" . $date . "&lt;/lastmod&gt;"."\n"; $xml .= " &lt;priority&gt;0.50&lt;/priority&gt;"."\n"; $xml .= " &lt;changefreq&gt;never&lt;/changefreq&gt;"."\n"; $xml .= "&lt;/url&gt;"."\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") &amp;&amp; ($offset &gt; -2000) &amp;&amp; ($offset &lt; 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 &lt;/urlset&gt; line back. fclose($sitemap); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload