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.

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

Also Read :  Get all checked Checkbox Values in AngularJS

How To Create Dynamic XML Sitemaps Using PHP?

<?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/adodb.inc.php';
  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 = 'https://www.pakainfo.com/web_site/';
  $site_timezone = 'UTC';
  $offset_timezone = '+00:00';
  $datetime_w3c_format = 'Y-m-d\Th:i:s'; // Display http://www.w3.org/TR/NOTE-datetime
  $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 http://www.sitemaps.org/protocol.html#escaping
      $live_posts[$pst]['url'] = $set_url_pfx . htmlspecialchars($live_posts[$pst]['url']);
      // convert Your PHP dates to W3C Simple datetime format http://www.sitemaps.org/protocol.html#xmlTagDefinitions
      $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="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
  echo $results;
?>
<url>
  <loc>https://www.pakainfo.com/web_site/</loc>
  <lastmod><?php print $max_date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<url>
  <loc>https://www.pakainfo.com/web_site/archive/</loc>
  <lastmod><?php print $max_date ?></lastmod>
  <changefreq>daily</changefreq>
</url>
<?php for($i = 0; $pst < $total_len; $pst++) { ?>
<url>
  <loc><?php print $live_posts[$i]['url'] ?></loc>
  <lastmod><?php print $live_posts[$i]['date_updated'] ?></lastmod>
</url>
<?php } ?>
</urlset>

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 :  Create Dynamic Sitemap Using PHP with Mysql

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)

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

Sitemap: http://www.yoursite.com/sitemap.xml
//Example
Sitemap: https://www.pakainfo.com/sitemap.xml

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.

Also Read :  Dynamically Add-remove Form Fields in jquery with PHP and mysql

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

Recommended For You.

Move Laravel Project From localhost to live production server
Today, We want to share with you Move Laravel Project From localhost to live production server.In this post we will

Add a Comment

Your email address will not be published. Required fields are marked *