Robots.txt – How to tutorial

SEO-robots.txt

Robots.txt is a way to tell search engine bots what to crawl and what not to.  This is just a text file and path to upload it is on your website web root folder so that bots can access it like http://www.yourwebsite.com/robots.txt. So when you add a robots.txt file, make sure it is accessible this way.

Why we need robots.txt file?

a) To block certain area of the websites for bots so that it wont be crawled.
b) To allow certain bots and disallow bad or unwanted bots.
c) Even use it to point sitemap url for bots.
d) Managing the crawl rate for bots to reduce server overload.

Creating robots.txt file

There are very few parameters or instruction for robots.txt file. They are User-agent, Disallow and Allow.

User-agent : is to tell bots which bots we are writing instruction for. If it is for all then we can use wild card * .

Allow / Disallow: this can be file, path to the folder, combinations of wild card e.t.c to allow and  disallow bots.

How to use robots.txt?

here are some examples:

a) To allow all the bots to the site.
just make the robots.txt blank page or

User-agent:*
Allow: /

b) To disallow all the bots:
User-agent:*
Disallow: /

c) To disallow specific bots.
User-agent: badBot
Disallow: /

d) To disallow specific folder
User-agent:*
Disallow: /foldername/

e) To allow certain file in disallowed folder
User-agent: *
Disallow: / foldername/
Allow: /foldername/myfile.jpg

f) Adding sitemap through robots.txt
Sitemap: http://mysite.com/sitemap.xml

g) Delaying the crawl rate
crawl-rate: 5

Each set of instruction should be separated by line gap. Here is the better instruction.

User-agent: *
Disallow: /thirdAuth/
Disallow: /sort
Disallow: /suggest
Disallow: /share
Disallow: /signup
Disallow: /img/
Disallow:/private/
Allow: /private/5384-*
Allow: /private/5385-*

Sitemap: http://mysite.au/sitemaps/sitemap.xml
user-agent: AhrefsBot
disallow: /

User-agent: TurnitinBot
Disallow: /

User-agent: SEOkicks-Robot
Disallow: /
User-agent: msnbot-media
Crawl-delay: 10

User-agent: FlipboardProxy
Disallow: /

User-agent: MJ12bot
Disallow: /

User-agent: UnwindFetchor
Disallow: /

User-agent: MetaURI
Disallow: /

User-agent: BLEXBot
Disallow: /

User-agent: msnbot-media
Crawl-delay: 5

For details you can visit http://www.robotstxt.org/wc/robots.html .

Difference between Interface and abstract class – PHP Tutorials

Many of us normally end up with confusion about interface and abstract class, so in this post i am trying to clear it out, and highlighting the usuages.

What is Interface?

Interface is just a interface as the name implies, it just a definition of objects and methods with no body  on it. So its a collection of objects and methods that can be used by other class to perform common function. So its a just a place to specify objects and methods but does not explain you, how it is used or defined.
Its a practice to make clear rules on class.

So in summary, interface doesn’t do any thing, its just a pattern to be follow.

Class can inherit more than one interface.

What is Abstract class?

Abstract class is little more than interface classes, it not only defines the objects / methods  but also explain, what it suppose to do as default.  It may / may not define all the methods so it can leave some of the method to be implement by those who inherits it. Class who inherits it can add more methods / objects, those are not provided by the abstract class unlikly to interface.

Objects of an abstract and interface class cannot be created.

Private methods cannot be define in Abstract class as its cant be used by classes using abstract.

What is the Difference between Abstract Class and Interface

  1. Can inherit only one abstract class but can inherit more than on interface.
  2. Abstract provides complete code but interface is just a pattern to be follow.
  3. Abstract class is faster as it has complete code while interface is just a pattern so more classes are loaded.
  4. If new method is added to abstract class, all class that inheriting might work but if we add method in interface we have to define method in all inherited classes.
  5. Class using abstract classes may / may not follow everything from abstract class and call add more  but interface must be followed.
  6. Class can overwrite the method of abstract class but interface we just follow the same.
  7. Completely non related classes can follow same interface but in abstract this may not be possible.

Example of Abstract Class:

abstract class Member {
    public $fname;
    public $lname;
    public $address;
    public $phone;

    public function addData($fname,$lname,$address,$phone) {
    }

    protected function getName() {
    return $this->fname.' '.$this->lname;
   }
}

Class using Abstract class:

class Employee extends Member {

    public $emp_name;
    public $emp_address;
    public $emp_phone;

    public funtion getFullName() {
        $this->name = $this->$emp_fname;
        $this->lname = $this->$mp_lname;
        echo $this->getName();
}                 
          public function someFunction() {        };
}

In above example, class inheritting abstract class Member 
is only using one method of the class. And also has some extra class on it. 

Example if Interface:

Interface  Member {

    public function addData($fname,$lname,$address,$phone);

}
class Employee implements Member {

    public $emp_name;
    public $emp_address;
    public $emp_phone;

    public funtion addData($fname,$lname,$address,$phone) {
        // code

        }                 }