Creating Dynamic XML Sitemaps Generator Using PHP MySQLi

Creating Dynamic XML Sitemaps Generator Using PHP MySQLi

Today, We want to share with you Creating Dynamic XML Sitemaps Generator Using PHP MySQLi.
In this post we will show you Building Dynamic Sitemap Using PHP, hear for Creating Dynamic XML Sitemaps using PHP we will give you demo and example for implement.
In this post, we will learn about SiteMap XML Dynamic SiteMap Generator Software with an example.

What is an XML Sitemap?

A Sitemap is one of Very Easy ways to Display Search or find your website online any Data or Content to the SEO – search engines like as Yahoo, Bing, Google etc.

Also Read This 👉   jquery Count Number of characters in string input

Almost all More information or Defination of the Sitemap, We need to know about More Sitemaps is available at here

How To Create Dynamic XML Sitemaps Using PHP?

  header('Content-type: application/xml');
  //Include External require files
  require_once '../common/settings.php';
  require_once YOUR_PROJECT_PATH . '/lib/php_adodb_v5.18/';
  require_once YOUR_PROJECT_PATH . '/lib/small_blog_v0.8.0/smallblog.php';
  require_once YOUR_PROJECT_PATH . '/lib/utils/utils.php';

  $set_url_pfx = '';
  $site_timezone = 'UTC';
  $offset_timezone = '+00:00';
  $datetime_w3c_format = 'Y-m-d\Th:i:s'; // Display
  $sitemap_null = '<urlset><url><loc></loc></url></urlset>';
  $web_site = new smallblog();  // custom websites engine
  $res = $web_site->db_connect($blog_db_settings);
  if($res === false) {
    echo $sitemap_null;
    exit; // Live Database connection error...
  } else {
    // get all live_posts meta-data
    $live_posts = $web_site->getPosts(0, 0, '', '', '', now($site_timezone));
    if($live_posts === false) {
      echo $sitemap_null;
      exit; // Error retreiving live_posts...
    $total_len = count($live_posts);
    for($pst = 0; $pst < $total_len; $pst++) {
      // entities encode URL according
      $live_posts[$pst]['url'] = $set_url_pfx . htmlspecialchars($live_posts[$pst]['url']);
      // convert Your PHP dates to W3C Simple datetime format
      $live_posts[$pst]['date_updated'] = date_decode($live_posts[$pst]['date_updated'], $site_timezone, $datetime_w3c_format) . $offset_timezone;
    // fetch max date
    $max_date = $live_posts[0]['date_updated'];
  $results = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  $results .= '<urlset xmlns="">' . "\n";
  echo $results;
  <lastmod><?php print $max_date ?></lastmod>
  <lastmod><?php print $max_date ?></lastmod>
<?php for($i = 0; $pst < $total_len; $pst++) { ?>
  <loc><?php print $live_posts[$i]['url'] ?></loc>
  <lastmod><?php print $live_posts[$i]['date_updated'] ?></lastmod>
<?php } ?>

How to submit Sitemap to search engines

1.First of all using the Any Most useful search engine’s Your URL submission interface user friendly (stands as Webmaster Tools)

Also Read This 👉   PHPMailer Sending Emails using PHP Code

1-Google Tools: Google Webmaster Tools
2-Bing Tools: Bing Webmaster Tools
3-Yandex Tools: Yandex Webmaster Tools
4-Baidu Tools: Baidu Webmaster Tools (Baidu is not English interface yet,so you will step by step convert hindi or english need Google translation on Google Translaters)

2.And then sending an HTTP request (see more)

3.and This sitemap used the location in your web site’s URL robots.txt Main file (Must submit means strongly recommended)

Also Read This 👉   Cross Header Access Control Allow Origin missing

after that, Please main root path put your File and include a statement like:


We hope you get an idea about Building Dynamic Sitemap Using PHP
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

We hope This Post can help you…….Good Luck!.