Monday, 6 March 2017

How to create dynamic XML sitemap and submit to google web master for indexing


In this tutorial I’ll tell you very important method to generate dynamic xml sitemap for your website and how can we indexed all our dynamic url in google search.

Every body wants to create website now days and generate some traffic fast. So this is the trick for smart geeks, The below script is tested by me and worked great for me.

Let me tell you my experience, I had aprox 2 lakh dynamic urls which i created from my database rocords and i want to index all urls in google search, So i have created a php script which pull records from database and create a dynamic url for each records.

Suppose we have a books table with their name and auther.

ID NAME                 AUTHOR
1 Book Name-1 Book Author-1
2 Book Name-2 Book Author-2
3 Book Name-3 Book Author-3

My task is to index all my books url with their author name in google search, so that if anybody is looking for same books then he can find me in google search. Google automatically crawl urls but if you want fast result then give it try.

Create file sitemap.php and paste below script after that upload your sitemap.php file in your project root directory, Your sitemap url will be http://www.example.com/sitemap.php

You can make changes in below script according to your need this is just for demonstration purpose.

sitemap.php

<?php
  header('Content-type: application/xml');
  $baseurl = "http://example.com/books/";
  $hostname = "localhost";
$username = "username";
$password = "password";
$dbname = "booksdb";
$con = mysqli_connect($hostname, $username, $password, $dbname);

 function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}

  $output = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
  echo $output;
?>
  <?php $query = "SELECT name, author, id FROM books WHERE  status=1 LIMIT 0, 50000";
    $result = mysqli_query($con, $query);
    $res = array();

    while($resultSet = mysqli_fetch_assoc($result)) { 

 if(!empty($resultSet['name'])) { ?>

<url>
  <loc><?php echo $baseurl.clean(trim($resultSet['name'])).'/'. clean(trim($resultSet['author'])).'/'.$resultSet['id']; ?></loc>
</url>
<?php }  } ?>
</urlset>

Now time to submit your xml sitemap to google web master.

Login into your google web master account and submit your site map.


How to create dynamic XML sitemap and submit to google web master for indexing


If you don’t know how to submit sitemap in google web master please follow this tutorial.




Sunday, 5 March 2017

How to make visible newly hosted websites in google search

How to make visible newly hosted websites in google search

Today we are going to discuss about a very important issue we face while we purchase and host our newly website and facing the issue with google search that why my website is not showing in google search.

SO here i am going to discuss about my experience what i do with my website to index in google search and got visibility in next 24-48 hours.


My steps to index my wordpress blog in google search super fast.

Note: Before doing below steps your website should be live.

Step-1: Create google webmaster account.

https://www.google.co.in/webmasters/

Steps-2: Create XML sitemap for your website and if you have normal html website there is lot’s of online XML sitemap generater tools are available on web like https://www.xml-sitemaps.com/

If your website in wordpress you can install some available plugins for generating XML sitemap for your website.

I used “Yoast” one of the best plugin for doing SEO of wordpress website. And generate XML Sitemap.

Step-3: Place your website XML sitemap on your web root directory using ftp if you used online XML sitemap generater tools.

Your sitemap map url look like www.yourWebsiteName.com/sitemap.xml
In case of wordpress YOAST it does this task automatically.

Step-4: Login into your google web master account and add your website by click on “ADD A PROPERTY” button and popup will open here add your website link and click on continue button.

Step-5: Now click on your added website you can add multiple website here. you’ll see the dashboard. Now click on crawl-> sitemaps in left panel and here you’ll see ADD/TEST SITEMAP button on top right corner.

Step-6: create robots.txt file and place this file in your website root directory via ftp.

What is robots.txt

robots.txt tells search engines which pages have to index and which are not.
You can read more about robots.txt from here http://www.robotstxt.org/

My robots.txt is

User-agent: *
Disallow: /wp-admin/

Where Disallow means i don’t want to crawl my admin panel in google search.

After creating robots.txt file place this file in your website root directory and check it
www.yourWebsiteName.com/robots.txt
Or use google web master robots.txt tester tool.

Now wait at least 24-48 hours your website will become start indexing in google search, You can check by this syntax in google search box

site:yourWebsiteName.com


Hope this tutorial will help you to index your website fast in google search.


Thursday, 2 March 2017

How to Quickly Extract Domain Name & it’s components from URL in PHP


In this quick tutorial, I am going to show you How to Quickly Extract Domain Name & it’s components from URL in PHP, In some cases of development you need to extract host name and it’s parameter individually, For parsing domain name you can simply use php parse_url function to extract domain name, It’ll not only return domain but also Parse the whole URL and return its components in associative array format.

See example below

$url =  'http://html-css-designing-tips.blogspot.com/page/?id=1&name=php';
var_dump(parse_url($url));

OutPut:

array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(15) "html-css-designing-tips.blogspot.com" ["path"]=> string(13) "/page/" ["query"]=> string(15) "id=1&name=php" }

Extract Domain Name

$url =  'http://html-css-designing-tips.blogspot.com/page/?id=1&name=php';
$result = parse_url($url);
echo $result['host']; // output: html-css-designing-tips.blogspot.com


HTML APIs: What They Are And How To Design A Good One

As JavaScript developers, we regularly forget that not everybody has a similar data as USA. It’s referred to as the curse of knowledge:...