Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Sitemap generator class

Here is Curl multi sitemap class, which can be used to generate multiple sitemaps by crawling sites

It can crawl one or more sites to retrieve its pages and follow links recursively and determine the addresses of all pages to include in a XML sitemap.

It can ignore given URLs to avoid crawling and including in the sitemap.

The class uses the Curl extension multi-request support to retrieve multiple site pages at the same time. More about it's efficiency here at comparing filegetcontents, curl and curl multi-request

The class may also notify Google, Bing, Yahoo, Ask and Weblogs when the sitemap is updated.

Here is an example of this class usage: SitemapGenerator.co.cc

Contents

Download

Example codes

<?php
//setting to no time limit, 
set_time_limit(0);

//declaring class instance
include("./sitemap.class.php");
$sitemap = new sitemap();

//optionally set proxy server name and port or ip and port
//comment-out or set to an empty string to disable proxy use
//$sitemap->set_proxy('10.1.1.1:8080');

//setting rules to ignore URLs which contains these substrings
$sitemap->set_ignore(
        array("javascript:", ".css", ".js", 
              ".ico", ".jpg", ".png", ".jpeg", 
              ".swf", ".gif"));

//parsing one page and gathering links
$sitemap->get_links("http://code-snippets.co.cc");

//parsing other page and gathering links
$sitemap->get_links("http://cms.annar2r.info");

//return URL list as array
//$arr = $sitemap->get_array();

//echo "<pre>";
//print_r($arr);
//echo "</pre>";

header ("content-type: text/xml");
//generating sitemap
$map = $sitemap->generate_sitemap();

//submitting site map to Google, Yahoo, Bing, Ask and Moreover services
$sitemap->ping("http://".$_SERVER['SERVER_NAME'].
                $_SERVER['REQUEST_URI']);

echo $map;
?>

Examples in action

Example scripts provided with package in action:

Method list

Ignore URL substrings

Back to method list

Method nameset_ignore($ignore_list)
DescriptionSet rules to exclude URLs from sitemap, which contains these substrings
Input parametersarray $ignore_list - array with *wildcards* as values to ignore
Example inputset_ignore(array("javascript:", ".css", ".js", ".ico", ".jpg", ".png", ".jpeg", ".swf", ".gif"))

Set proxy

Back to method list

Method nameset_proxy($host_port)
DescriptionSet proxy host and port
Input parametersstring $host_port - profy host and port , for example someproxy:8080 or 10.1.1.1:8080
Example inputset_proxy("10.1.1.1:8080")

Get links

Back to method list

Method nameget_links($domain)
DescriptionParse provided url to collect all urls from same domain
Input parametersstring $domain - url to website
Example inputget_links("http://code-snippets.co.cc")

Get array of URLs

Back to method list

Method nameget_array()
DescriptionReturn array of all colected urls after calling method get_links
Input parametersstring $domain - url to website
Example inputget_links("http://code-snippets.co.cc")

Notify services about your sitemap update

Back to method list

Method nameping($sitemap_url, $title ="", $siteurl = "")
DescriptionNotifies services like Google, Yahoo, Ask, Bing and Moreover about your sitemap and sitemap updates
Input parameters

string $sitemap_url - url to generated sitemap

string title - your website title (optional)

string $siteurl - URL to your site (optional)

Example inputping("http://code-snippets.co.cc/sitemap.xml", "Code snippets", $siteurl = "http://code-snippets.co.cc")

Generate XML sitemap

Back to method list

Method namegenerate_sitemap()
DescriptionGenerate XML site map based on method get_links collected URLs and returns it as string

Possible error messages

List of all errors and meanings

Error textMeaningSolution
Provided file IMAGE_PATH isn't correct image formatFile you are trying to add isn't image, or has unsupported format.Convert it to any supported format, like png, jpg or gif
Provided file IMAGE_PATH doesn't existFile you are trying to add doesn't existCheck your specified path and/or file/directory permissions

Latest changes

15.09.2010 - added proxy support

Rate us

Like our script? Rate it at PHP > Hot Scripts

Scripts.com
RATE ME!

Try it out and Rate on PHPclasses.org

Support

PHP classes support forum or comments below

Awards

Curl multi sitemap was nominated to Innovation Award and achieved 5th place, thanks everyone for voting


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus