Create Dynamic XML Sitemaps Using PHP MYSQL

Create Dynamic XML Sitemaps Using PHP MYSQL

In this Post We Will Explain About is Create Dynamic XML Sitemaps Using PHP MYSQL With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to xml – Creating dynamic sitemap with php and MYSQLExample

In this post we will show you Best way to implement Creating Dynamic XML Sitemaps using PHP, hear for Make Dynamic XML sitemap in PHP Scriptwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :  WordPress Security Tricks to Secure WordPress Website

Database

-- Table structure for table `dynemic_page`

CREATE TABLE IF NOT EXISTS `dynemic_page` (
  `dyn_page_id` int(11) NOT NULL,
  `custom_page_title` text NOT NULL,
  `my_page_url` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;

ALTER TABLE `dynemic_page`
  ADD PRIMARY KEY (`dyn_page_id`);
  
ALTER TABLE `dynemic_page`
  MODIFY `dyn_page_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=11;
  
-- Dumping data for table `dynemic_page`

INSERT INTO `dynemic_page` (`dyn_page_id`, `custom_page_title`, `my_page_url`) VALUES
(1, 'Vuejs Hello World Example | Introduction — Vue.js | Vuejs Example', 'vuejs-hello-world-example-introduction-vue-js-vuejs-example/'),
(2, 'Angularjs autocomplete Textbox example – Autocomplete Directive', 'angularjs-autocomplete-textbox-example-autocomplete-directive/'),
(3, 'AngularJS and CRUD Using RESTful APIs Example\r\n', 'codeigniter-tutorial-hello-world-example-steps/'),
(4, 'AngularJS Form Validation Example\r\n', 'angularjs-form-validation-example/'),
(5, 'jQuery Basic Selectors with Adding a class to even an odd List-Elements\r\n', 'jquery-basic-selectors-adding-class-even-odd-list-elements/'),
(6, 'dependable Country-State-City Cascading dropdowns in AngularJs\r\n', 'dependable-country-state-city-cascading-dropdowns-angularjs/'),
(7, 'JSON Encoder and Decoder For JavaScript with Example\r\n', 'json-encoder-decoder-javascript-example/'),
(8, 'AngularJs Application Folder Structure\r\n', 'angularjs-application-folder-structure/'),
(9, 'How to Add and remove active class on click using AngularJS\r\n', 'add-remove-active-class-click-using-angularjs/'),
(10,'http POST method request and response in angularjs\r\n', 'http-post-method-request-response-angularjs/');  
  

sitemap_index.php

<?php 
//sitemap_index.php
$db_connect = mysqli_connect("localhost", "root", "live#$%^24u", "Pakainfo.com");

$sql_query = "SELECT my_page_url FROM dynemic_page";

$data_result = mysqli_query($db_connect, $sql_query);

$start_url_base = "http://pakainfo.com/tutorial/php-sitemap/";

header("Content-Type: application/xml; charset=utf-8");

echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; 

echo '<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">' . PHP_EOL;

while($data_row = mysqli_fetch_array($data_result))
{
 echo '<url>' . PHP_EOL;
 echo '<loc>'.$start_url_base. $data_row["my_page_url"] .'/</loc>' . PHP_EOL;
 echo '<changefreq>daily</changefreq>' . PHP_EOL;
 echo '</url>' . PHP_EOL;
}

echo '</urlset>' . PHP_EOL;

?>

Also Read :  Date filtering and formatting in VueJS with Example

.htaccess

RewriteEngine On

RewriteRule ^sitemap\.xml/?$ sitemap_index.php

Example

I hope you have Got What is xml – Creating dynamic sitemap with php and MYSQL And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Reply

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