Sitemap Creator

Started on the old forum in October 2009 · view the original in the archive · old links redirect here

No replies · 502 views · started 17 years ago · 1 min read

blackhowk Senior · 411 posts #1

The Sitemaps protocol allows a webmaster to inform search engines about URLs on a website that are available for crawling. A Sitemap is an XML file that lists the URLs for a site. It allows webmasters to include additional information about each URL: when it was last updated, how often it changes, and how important it is in relation to other URLs in the site.

first part should be put on the main page of the site, forum, etc. in an environment with no access by logging for example config-website. we ensure this way that the script is run at any time. the second part shall be in an area protected from logging for example in the area of administration. this part creates the sitemap.xml and under this settings. xml must be in your site root. as you can see there a clause $creator == 'yes' it will be activated only to access the entire site at once. in this way to avoid injection into mysql. as do all the links to join the site db? use WinHTTrack Website Copier HTTrack Website Copier - Offline Browser after insertion in the set and his visit WinHTTrack Website Copier set $creator = "no", and execute the second script.

  • part 1.
<?php
// copy paste this part into your main site
// database structure
/*  
  CREATE TABLE `map` (
  `id` int(255) NOT NULL auto_increment,
  `link` text NOT NULL,
  `md` varchar(32) NOT NULL default '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `md` (`md`)
) ;
*/

// enable creator of sitemap - yes or no
$creator = "yes";

// read url's 

function selfURL()
{
$s = empty($_SERVER["HTTPS"]) ? ''
: ($_SERVER["HTTPS"] == "on") ? "s"
: "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
: (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2)
{
return substr($s1, 0, strpos($s1, $s2));
}

// the same **** but with blue eyes
//$url = $_SERVER['QUERY_STRING'];

if ($creator == 'yes'){ 
// get url
$url = selfURL();
// make md5
$md5 = md5( $url ); 
 
// insert into database sitemap
   $insert_map = "INSERT INTO `sitemap` ( `id` , `link`, `md` )
VALUES (NULL, '$url', '$md5');   ";
  mysql_query($insert_map);  
}

?>
  • part 2.
<?php
// copy paste this part into your site protected by login zone
// connection to your database
/*
your connection here
*/
// filename of sitemap
$filename = 'sitemap.xml';
$ss = "SELECT `link` FROM `sitemap` ORDER BY `id` ASC";
$result = mysql_query($ss);

// sitemap header 
$somecontent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<urlset
      xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
      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\">\n\n"; 
            
// select from database           
while(list($l) = mysql_fetch_array($result))
{ 
 
//put the content correct  
$string = ereg_replace('&', '&', $l);
$somecontent .= "<url>
<loc>$string</loc>
<priority>0.5</priority>
<changefreq>hourly</changefreq>
</url>\n"; 
   }  
// close sitemap
$somecontent .= "</urlset>";

// make the file, if it exists it will overwrite it
$fp = fopen($filename,"w") or die ("error opening file .xml");
// set the content into the file
fputs($fp,$somecontent);
// close the file
fclose($fp); 
?>

can change and adapt content for mobile sites sitemap - see sitemaps.org - Protocol

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close