Adsense Invalid Traffic took US $125

Many of you might not have heard of this before. There is a concept of Adsense Invalid Traffic in Google’s algorithm. I came to know about this concept recently when I saw a heavy deduction in my adsense earning. US$125 was deducted from my adsense account in the previous month because of this invalid traffic. Google also keeps a track of the surfing pattern of all the visitors to your website. This includes the type of people (traffic) that your website is generating. Source of those visitors, exits of those visitors and all sorts of metrics which you would not want to know of.

 

US $125 deducted due to Adsense Invalid Traffic

Adsense Invalid Traffic
US $125 deducted for Invalid Traffic

Recently, when I saw a heavy deduction on my adsense accounts I begin researching into it. Though I was not the first one to face such an issue but it was my first time and it was my duty to find the source for this deduction. When I analyzed the visitors demographics and origin. I found that 64% of the traffic that I generated last month was from social websites such as Facebook, Google, LinkedIn, Twitter etc… This type of traffic is not very productive for your blog. To state it in their terms, The Adsense guys calls it ‘CRAP TRAFFIC’, meaning this traffic is of no use to the advertisers, therefore, they do not want to pay for such kind of traffic. And it is of no use to them. So, when the advertisers doesn’t pay to google, google doesn’t pay us. Equation is simple.

This issue was first raised somewhere around year 2006-07 when there was a sudden increase in the social networking websites. A lot of traffic was generated from these sources and as a result advertisers became unhappy. To keep this in control google came up with the algorithm which checks the source of traffic coming to your website and all sorts of different metrics we don’t know yet.

 

Why Social Networking Traffic is a CRAP TRAFFIC

The Adsense Guys think that people who come from any social network is not a legitimate user. They are surfing on social websites just to pass their time and whenever they see any attractive link, they click on it. These people have no intention of buying their product. They click links just out-of-curiosity which impacts the advertisers money. Therefore, they termed it CRAP TRAFFIC because for them it is of no use.

 

What do we learn from this?

There is one important thing that we know for sure that the traffic generated from social networking sites adds no value to your overall earning. You must device your marketing strategy in a way which will attract organic traffic to your website. I know organic traffic is not that easy and not everyone is blessed with it. But now as we know this fact so we can try to generate traffic of legitimate users.

Also, I found that google’s algorithm behaves pretty much like a human mind. It is kind of beneficiary for us to strategise our marketing patterns. Now, you do not have to think from a computer’s point of view. You just have to think for your people and that is all you need to do. This is also a major factor in your SEO. SEO experts at Google always talk about human first. They always ask you to write for humans not for machine and this thing has become somewhat clear. That the more you think about people, the better it is for your blog’s health.

 

Please share you insights on Invalid Traffic and how do you generate traffic for your website. What is your take on this one?

And as always,
Be my aficionado 🙂

 

Basics to Start Website Anywhere

Hey guys, if you are looking forward to start website of your own then there are a few target areas which you must target to give your website a boost. I first started blogging because I was really passionate about putting my thoughts in front of the world. I didn’t knew much about blogging. At that time I never knew the potential that blogging can become your full time career. Slowly and steadily when my website started getting visitors, my interest grew. I started exploring different aspects of blogging. There are alot of things that a beginner is not aware of before starting a website. Things which comes before you start a website.

Before Starting a Website

There are a lot of things that needs to be checked before starting a website. If you are blogging for yourself, or you are looking forward to make some money out of your blog, or if you trying to make a community or an organization.

Purpose of your website

The very first step even before you start your website, you need to ask yourself the purpose of this website. What this website is going to do and how it is going to make a difference. You need to be very clear with the purpose for your website because at last your purpose is what you are going to become.

Domain Name

There are a few things that you must keep in mind before purchasing a domain name. You are clear with the purpose, now you can easily decide what you website is going to be about.

DOT COM (.com)

If you are planning to make money out of your website then you must go for a .com domain. Dot com domains are there from the beginnning. Organizations, companies, universities, ecommerce website all go for a .com domain because it puts weight to your website. Search engines have some affinity towards a .com domain. It results in quick indexing and global presence. A .com domain is a global domain and is available to every part of the world. So, while you are thinking of a name for your website make sure you keep domain part in mind. Find out more at wiki.

DOT IN (.in)

DOT IN domain usually represents India. If you are looking forward to create a website that you think is going to do it’s business in India then this will give you a little more weight over .com as I see. Search engines segregates search results based on the geographical region of the website. So, if your domain ends in (.in), it is most likely that your website is going to come up first. I have made a few top search results in Indian search but the same is not applied to other parts. This has been my experience so far. So, if you are proud indian and want to explore this huge Indian market then go forward with this domain. Read more at wiki.

DOT ORG (.org)

It represents an organization. If you are an organization then this will be your best choice. See you have to be clear about your website from the start. If you know what you are doing is going to come out as an organization then you should choose the same for your website. If you are not sure what your website is going to be in the future then a (.com) domain would be a better choice. But then again it all comes to the purpose of your website. Read more about this domain in wiki.

DOT NET (.net)

It represents a network. The name is derived from the word network, indicating it was originally intended for organizations involved in networking technologies, such as Internet service providers and other infrastructure companies. However, there is no restrictions on its use. It can be used as a general purpose namespace. You can read more about it here.

Target Audience

target your audience

You know the purpose of your website, very good. Now you must decide your target audience. Another important step in the making. Who are you going to write for? Who all are going to interact with your website? Answers to these question will help you create content good content. You will write to the point because you know whom you are talking to. That really makes a difference if you’re clear about your target audience.

Different audience have different style of reading and different ways to apprehend. Once you are clear about your audience, you will see your style of writing changes. It’s just like you talk differently to an old man and totally different with a kid. So, once you know the target audience, it will automatically reflect in your blog style.

After Starting Your Website

You have followed all the above steps, good. Now, it’s time to create content for your website. When I first started blogging I saw I had a few visitors only and that too were the ones who came by direct clicking on links I shared on social media and other places. I was a noob back then. I started researching about increasing visitors on my website and then I came to know about SEO. SEO is a tool by which you can attract organic traffic to you website.

Search Engine Optimization (SEO)

SEO

Once you start writing your articles for your website than the first most important thing that comes into the picture is making your blog available to your audience. Your content must be easily indexable by search engines. Search engines must be able to search you and index you accordingly. This is not gonna happen by itself. You will have to follow the best practices to make your website stand out from millions other. SEO is really a vast field. It has become a career in itself. I understand many of you does not have time to delve into yet another field. You do not have to worry about it as well. If you are using a wordpress to create your blog then their many plugins that will do the most important of the work for you.

Some of the plugins that did the job for me is SemperPlugin and Yoast SEO. Both of these plugins makes your job real easy. WordPress themes also playes a major role in ranking you better on search engines index. I have created this theme which I have named Whitehogan. I will make it available to all you after the housekeeping work is done. I’m still working on it at the moment. There are many free plugins to choose if you are using wordpress. If you need assistance for for website creation or wordpress setup then do contact us. We are ready to help you.

If you wish to read more about basic SEO that you can use in you website then I have already talked about the basics of SEO in my earlier blog posts. Please refer to that article before start writing.

For a deep understanding of how things work or not you may contact us. You can contact us if you need consultation regarding your website SEO. My team and I are always excited towards our clients.   

Content is King

content is king

You have done all the above steps, chances are you might not get the best of result because this is the most important of all the steps. It has always been the content regardless of whatever you do. Content has always been the king. You must spend your time in curating the best of the content which is actually going to help others in the subject in which you are writing about. There are thousands of other websites which are doing all the above steps. It is just the content that is going to make you stand out from others. So, pay close attention while creating the content.

There are various tools available that can help you in creating good content. Grammarly is one of my favourite online grammar checking tool. It really helps me to improve my efficiency while I concentrate on creating content. Grammarly offers you grammar checking for free once you sign up. For advance features you will have to pay a small fees which is worth if you are going to write a lot everyday.

Another thing that I make sure is my place and mood. However, I only sit and write when I’m in a good mood and feels like writing something. Until and unless it’s not going to come from inside, it’s not going to come out the best. So, just make sure you are writing with all you heart and mind. Distractions are never good for focus. Make sure you are in a place where you can spend all your time creating quality content. It is more for you mind than yourself.

Conclusion

This was just the tip of iceberg. As I dig inside I come out surprised. There is so much to learn in this field. Everyday I’m faced with new technologies and updates and I have to do research to make the most out of it. It’s not a one day job, you have to give constant efforts to make yourself better everyday. Some of the bloggers whom I praise is Harsh Agarwal and Amit Bhawani. They have made their fortune in the field of blogging by following their true passion. Who is your idol? Share your views in the comments below. Also, if you need any further assistance simply comment below.

Here are some articles to help you with the hosting,

And as always,
Be my aficionado 🙂

SEO – How Search Engines Work

I asked  a kid for the definition of Internet and he replied – “Google is the Internet”. This is an answer I wasn’t expecting at all but this thing made me wonder the importance of Search Engines and the wonders it has brought into everyone’s life. It is one of the biggest invention after the Internet itself. In fact, Internet and Google are so tightly linked together that anyone would easily get confused between these two. It is our default homepage, it is the first page from where we find our way on the internet. It is the most viewed page on the internet. Therefore, there is a need to learn SEO & How Search Engines Work.

Ever imagined a life without Search Engines? How did we search the contents we want? What would happen to the flow of information? The world will simply shrink up. There will be no common place from where you can easily find the information you want. Then people will have to maintain separate dictionaries for different websites and it will all become unmanageable and time-consuming. Hopefully, we have search engines to solve our queries.

How Search Engines Work

There is two most important job which is at the heart of every Search Engine. The first job of a search engine is to CRAWL and the second most important job is to INDEX. Let’s understand each one by one.

CRAWL   

Search Engines - Crawl Weboage

The Internet is a big network which consisting millions of websites. Each website has connecting links to page or websites present on the same network.

Imagine you are on a tour to some city. You need some kind of transportation medium to move from one place to another. Consider each stop as unique document (i.e, a webpage, a document, etc…). You need a way to crawl entire city and visit all the stops. The best possible way to accomplish this are the buses (LINKS) that will take you from one stop to another. This is how Search Engines work.

Search engines crawl your webpage and every other interconnecting links present on that page. It does it similarly to a human but only faster (way too fast). This is how search engines visit each and every link of your website.

INDEX

Search Engines - Search Engine Indexing

Crawling is the process of finding different pages on the internet. Once the pages are crawled and the information has been retrieved then this information is saved in the massive database. Indexing is the process to accumulate this information in a structured way which is efficient to retrieve later. It is similar to the process of indexing library books with their author, date of publish and much such information but it is done on a very large scale. You simply cannot imagine the amount of indexing done each minute. Here are the stats –

  • In 1999, it took Google one month to crawl and build an index of about 50 million pages.
  • In 2012, the same task was accomplished in less than one minute.

Can you imagine the index rate now… Phewww… Un-imaginable.

The amount of data produced is needed to be structured and stored somewhere in order to efficiently process it later. Complex algorithms are used to process queries from thousands of servers located worldwide to provide the relevant search results to the user. If you are curious to know more than read Google Search Statistics.

Relavance and Popularity

Search Engines - Relevancy and Popularity

In the early days of search engines, finding relevant search result was no more than finding the matching keywords. As search engines advanced, they have become more intelligent than ever. Engineers have devised better algorithms and relevancy of the content is affected by hundred of different factors.

In the early stage, the relevancy was found by analysing the frequency of keywords used in the article. This was exploited by overuse of the keywords which is known as “Keyword Stuffing”. This anomaly was solved by inventing new ways to rank pages. One such way is to view the number of backlinks to a website. The more referrals a website get, the more relevant it is thought to be. But this algorithm was also cracked and the number of links started to grow up immensely all around the web. Thus resulting in the bad search result.

The algorithm was further modified to keep the weight of that particular link. Suppose, your website has been referred from some reputed website who ranks high and is related to the context of your article, then it is of more importance to the search engine than any other less known website. Therefore, fake links will not work anymore.   

Nowadays the algorithms are so complex and deal with thousand of different variables that it is very hard to crack. These algorithms are kept hidden as there will be people trying to hack it and use it in unfavourable ways. From past 4 years, google has managed to keep it secret and has been successful in keeping the algorithm shrouded.

 

Bottom line – Make Content for People and not for Search Engines

Conclusion

How to get some success rolling in your favour. Well, follow these guidelines by Google Webmaster.

  1. Primarily make content for users and not for search engines.
  2. Do not try to deceive search engines by showing the different result to the user, a technique commonly knows as “cloaking”.
  3. Make a website with clear hierarchical links which are easily indexable by the search engines. Must provide a sitemap to the search engines which will reduce the job of search engines and able to better structure your webpages.
  4. Make sure you follow the proper guidelines for creating valuable content. Follow this article which will tell you about making your content SEO friendly. Tips for making your pages SEO Friendly.
  5. Use keywords to create more descriptive human friendly URLs. Avoid use of stop words in the URL. Read more about stop words here.

 

Go through this video for a more descriptive visual and audio presentation of the concept.

 

 

I hope I have made the concept clear for every budding individual wants to know about the process search engines follows to give the most relevant and popular search results. If you want to add anything to the above content then do comment below.

 

Be My Aficionado 🙂

 

SEO – Tips for Beginners

This article is for everyone who is new to the world of blogging or internet. Well, In short, SEO stands for Search Engine Optimization. It is a process through which search engines like google sees your website and index them. SEO plays an important role in listing your website on the front of google search page. If you master this skill then you will no longer need social websites to bring traffic to your website or blog. You will get organic traffic through google and that’s the best way to bring your visitors to the website. The better you are ranked on google search list, more visitors you will get.

SEO – Tips for Beginners

SEO Banner

Few things that must not be overlooked, you must always concentrate first on creating good content. Google bots are smart enough to tell whether the content is useful or not. This is the very first and the most essentials step that you should keep in mind while writing your blog or while you create your webpage. It should be for the humans and not for the search engine bots. Invest all time in creating a content that is useful for the people. Now, few SEO tips that you can follow to make you blog stand out.

  • Limit Title to 160 Chars

    title-description

    Make sure your blog title is less than 160 chars. Because that is the default length which is going to show up when your page is listed in a google So, make sure you are in the range and also spend quite some time to come up with a catchy title. After all, humans are going to read and it should attract them to your blog or website. For more info on meta description follow this link, Meta Description Tag

    NOTE: Google uses meta descriptions to return results when searchers use advanced search operators to match meta tag content, as well as to pull preview snippets on search result pages, but it’s important to note that meta descriptions do not to influence Google’s ranking algorithms for normal web search.

  • Provide the description for your Webpage

    <head>
    <meta name="description" content="Here is a description of the applicable page">
    </head>
    

    Meta description plays a vital role when it comes to SEO. Make sure your description contains the summary of your article or page. Google pays attention to the description of the page and it gives you more control over your article. Do not try to fool bots by the false description in order to get traffic. Just make sure your description is a summary of your article. It should be authentic.

  • Insert Images | Make it Visually Attractive

    Make sure you have images on your page with the alt attribute. Alt is an alternative name for the image. If the google could not understand the meaning of the name it reverts to the alternate name for the image. The images should be very well optimised in all aspects, especially size. Reduce the size of the image to make it load faster. Try to use the exact dimensions if possible. If your image is going to be displayed in 400×400 then there is no use to download an HD 2048×2048 image, this will indefinitely increase the load time of a website. And as per the research, an average person waits 3-4 seconds on a page. If possible, then use lazy load for images. So, make sure your alt attribute defines the picture you have on your website. Check out this article  Travelling Tips for a Foodie

  • Try to Reach a Minimum Threshold

    Your page should contain more than 300 words. Though it is not a must condition but an above 300 words articles has more chance of listing then a less one. Again, it is not mandatory but a good practice, so if you can get it more than 300, DO IT!

  • Insert Valuable Links

    There are mainly two types of links-
    – Internal Links
    – External Links

    Internal Links – Search engines are very keen on internal links to make their jobs easier. Search spiders go through your content and search for connected links to insert into their database of indices. This helps search bots to index your website into their database and to understand the semantic relationship between two or more links.Hundreds of thousands of sites make the critical mistake of hiding or burying their main link navigation in ways that search engines cannot access. This hinders their ability to get pages listed in the search engine’s indices. For more information on internal links follow the link, Internal Links – Best SEO Practices

    Internal Links

    External Links – Your article or page must contain links to the useful source. Outward links are helpful, essentially if you are linking your article to some reputed website such as Wikipedia, then google sees that and ranks your page higher. Google first made its mark by introducing the Stanford community to PageRank (an algorithm developed by Google co-founder Larry Page). This algorithm counted hyperlinks as votes for popularity. The pages that had the most links pointing at them were considered the most popular. When they were deemed relevant for a particular query, the most popular and relevant pages would become the first pages listed in Google’s results. Although this algorithm is much more complex today, it still likely includes the notion of external links as votes. So, make sure you give reference to other sites and pages outside your website and in turn get them to point at yours. This way you increase your reputation and google will rank you higher. For more info follow the link, External Links – Best SEO Practices

  • Provide Focus Keywords

    Do not forget to mention the focus words for your article. Focus words are simply the keywords that you want to relate your page too. You would want to choose high-frequency keywords because that’s what people search frequently. You can take help from Google AdWords for high-frequency search words. Also, make sure that the focus words are used in most of the places in your content. Suppose you choose focus word as SEO then SEO should be used at multiple times in your description. This increases the chances that your article will be marked high by the search bots.

Conclusion

These are a few SEO tips which you can start implementing in your articles and web pages today. You do not need to be expert to follow these simple tips. Just make sure that you follow this guideline while crafting your article and you will surely see the difference. SEO is very important if you are looking to earn from your visitors because SEO is the best way to drive organic or natural traffic to your website or webpage. Pay extra attention with the visibility of your webpage for the visitors. After all, you are writing for the people and if they didn’t see it then there’s not much point to it all.

Change your focus from making money to serving more people. Serving more people makes the money come in.
Tweet: Change your focus from making money to serving more people. Serving more people makes the money come in.

You may also like these articles,

Cheers 🙂

Basic Authentication with PHP & MySQL

Lately, I have been receiving a lot of emails on how to create a basic login and registration system by using plain PHP and MySQL. I have made this series just to teach you about the Basic Authentication, i.e. registering a user into the database and then logging the user to the system. We will also encrypt the password using PHP’s native function which uses the Bcrypt Algorithm. In a nutshell, this series will contain seven videos. What will you learn? At the end of this series, you will learn to create a basic authentication system for your application using PHP and MySQL.

  1. Create Database Schema and Folder Structure
  2. Create a Simple Login Page
  3. Create a Simple Registration Page
  4. Create Connection with the database
  5. Register User in the Database
  6. Authenticate User into the System
  7. Securing Pages from Invalid User

Create Database Schema and Folder Structure

Step 1. Create a Database with the name tutorials

create-database

Step 2. Create a table inside the tutorials database with the name t_login

--
-- Table structure for table `t_login`
--

CREATE TABLE `t_login` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(500) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `t_login`
--
ALTER TABLE `t_login`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `t_login`
--
ALTER TABLE `t_login`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

Step 3. Create Folder Structure to work with

folder structure




Create a Simple Login Page

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php 
$title = 'Login Page';
include 'includes/_header.php';
?>

<div class="container">
    <div class="row">
        <div class="col s1"></div>
        <div class="col s10">
            <form method="POST" action="process/authUser.php">
            <table>
                <tr>
                    <th>Login Form</th>
                </tr>
                <tr>
                    <td>Username</td>
                    <td><input type="text" name="username"></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="password"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><button type="submit">Login</button></td>
                </tr>
            </table>
            </form>
        </div>
        <div class="col s1"></div>
    </div>
</div>

<?php 
    include 'includes/_footer.php';
?>

Create a Simple Registration Page

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php 
$title = 'Registration Page';
include 'includes/_header.php';
?>

<div class="container">
    <div class="row">
        <div class="col s1"></div>
        <div class="col s10">
            <form method="POST" action="process/registerUser.php">
            <table>
                <tr>
                    <th>Registration Form</th>
                </tr>
                <tr>
                    <td>Username</td>
                    <td><input type="text" name="username"></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="password"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><button type="submit">Register</button></td>
                </tr>
            </table>
            </form>
        </div>
        <div class="col s1"></div>
    </div>
</div>

<?php 
    include 'includes/_footer.php';
?>

 

Create Connection with the Database

This class contains all the business logic for the application that deals with the database transaction. This way the code looks cleaner and more maintainable.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php


class DBConnect {

    private $db = NULL;

    const DB_SERVER = "localhost";
    const DB_USER = "root";
    const DB_PASSWORD = "";
    const DB_NAME = "tutorials";

    public function __construct() {
        $dsn = 'mysql:dbname=' . self::DB_NAME . ';host=' . self::DB_SERVER;
        try {
            $this->db = new PDO($dsn, self::DB_USER, self::DB_PASSWORD);
        } catch (PDOException $e) {
            throw new Exception('Connection failed: ' .
            $e->getMessage());
        }
        return $this->db;
    }
}

?>

The above code is used to create connection with the database. It uses PDO class, the PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. It is the preferred way for making connection to the database.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php


class DBConnect {

    private $db = NULL;

    const DB_SERVER = "localhost";
    const DB_USER = "root";
    const DB_PASSWORD = "";
    const DB_NAME = "tutorials";

    public function __construct() {
        $dsn = 'mysql:dbname=' . self::DB_NAME . ';host=' . self::DB_SERVER;
        try {
            $this->db = new PDO($dsn, self::DB_USER, self::DB_PASSWORD);
        } catch (PDOException $e) {
            throw new Exception('Connection failed: ' .
            $e->getMessage());
        }
        return $this->db;
    }

    // encrypt the password and create a new entry into the database
    public function saveUser ($username, $password) {
        $newPassword = password_hash($password, PASSWORD_DEFAULT);

        $sql = 'INSERT INTO t_login (username,password) VALUES (?,?)';

        $stmt = $this->db->prepare ($sql);

        return $stmt->execute ([$username, $newPassword]);
    }

    private function checkUserByUsername ($username) {
        $sql = 'SELECT * FROM t_login WHERE username=?';

        $stmt = $this->db->prepare ($sql);

        $stmt->execute ([$username]);

        $user = $stmt->fetchAll();

        if (count ($user) == 1) {
            return $user;
        }

        return null;
    }
    public function authUser ($username, $password) {
        $user = $this->checkUserByUsername ($username);

        if (! empty($user)) {
            if (password_verify ($password, $user[0]['password'])) {
                session_start();
                $_SESSION ['userID'] = $user[0]['id'];
                $_SESSION ['username'] = $username;
                return true;
            } else {
                return false;
            }
        }

        return false;
    }
    
}



?>

In this class, we create a constructor which holds the code for making connection to the database. As soon as the object of this class is created, it gets initialized and a connection to the database is made. A separate class for holding database connection and all the related business logic helps to maintain the modularity of the application.

Register User in the Database

Create a file with the name registerUser.php. The registerUser.php file lies inside process folder. This file is responsible for receiving the data sent from the registeration form with the help of $_POST superglobal variable. We pass the name of the input field we want to fetch the data from and save it to its corresponding variable.

Then we load the DBConnect.php class which resides inside classes folder and create its object. We use the object to access the function that we created inside of the DBConnect class.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php

$username = $_POST['username'];
$password = $_POST['password'];

require_once ('../classes/DBConnect.php');

$db = new DBConnect ();

if ($db->saveUser ($username, $password)) {
    echo "<h2>You have been registered Successfully!</h2>";
    header('Refresh: 2;url=http://localhost/tutorials/basic-auth/home.php');
    die();
} else {
    echo "<h2>There was some problemo!</h2>";
    header('Refresh: 2;url=http://localhost/tutorials/basic-auth/register.php');
    die();
}

Authenticate User into the Database System

Create a file named authUser.php inside your process folder and paste the following code in it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?php

$username = $_POST['username'];
$password = $_POST['password'];

require_once ('../classes/DBConnect.php');

$db = new DBConnect ();

if ($db->authUser ($username, $password)) {
    echo "Login Successful! Redirecting...";
    header ('Refresh: 2; url=http://localhost/tutorials/basic-auth/home.php');
    die ();
} else {
    die("Invalid Credentials");
}




Securing Pages from Unauthorised User

If the login is successful we would like to send the user to his/her profile or home page. We do not want any intruder to access the page without having to pass through proper login. Therefore, the pages must only be accessible if the user has been authenticated successfully. For that we must provide some sort of authentication on each page to prevent unauthorised users from accessing it. We do this by using session variables.

Create a new file in the root folder and give it a name as home.php. Copy the following code into the file and save it. Then navigate to the home.php file without passing through the login form and you will be redirected back to the login form. Now, try again, but this time through the login form and you will be able to access the page successfully. 🙂

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php

session_start ();
if (! isset ($_SESSION['userID'])) {
	header ('Location: http://localhost/tutorials/basic-auth/');
	die ();
}

include ('includes/_header.php');

?>

Welcome <?= $_SESSION['username']; ?>


<?php
	include ('includes/_footer.php');
?>

Conclusion

I hope you learned the basic authentication successfully. If you have any problem or any query, then you may comment below. I will be very active to solve any of your queries and help you grasp each and every part of it.

For full tutorial series, visit our youtube channel, and don’t forget to subscribe.

One Life, Rise & Shine
Cheers 🙂

Best Way-Port Codeigniter to WordPress

Porting a website to a different platform is not a piece of cake and I’m sure many of you will agree on this with me. Things become more curled up when you have to port your existing website to another platform. To port Codeignitor to WordPress is one of the same problems. In this article, I will walk you through all the problems that I faced when I ported my website to WordPress.

Let me start by giving you a brief explanation why I needed to port my existing website to the WordPress platform. Just to let you know, I was pretty happy with my website, I’m a web-developer and I really like to write each piece of code by myself that way I can control the quality of the website and performance. The need started to build up when I needed to make changes to my website. I had to get to code the pieces and bits myself even for a tiny addition to the functionality of my website. I did create a solid backed for blogging and media management but soon I realised that I cannot always do everything on my own. It takes a time to learn a new skill and then it takes more time to perfect it. And especially when you have your client’s work left over. So, it was becoming a tedious and time-consuming time for me. Instead of writing articles, my time was elapsed in coding. After all, Codeignitor is not a CMS (Content Management System), it is used to build the application that will serve a particular need and perform a particular task for what it is built for. So, I decided to port my website to WordPress.

Best Way-Port Codeigniter to WordPress

Porting is something I had never done before. This was my very first time. I sure read a lot about porting and that things really did help me but you know, theoretical knowledge cannot beat practical experience. I was porting my existing CodeIgniter project to WordPress on the same domain and to a new server. Yeah, I saw it an opportunity and ported my website to a whole new server as I was not completely satisfied with the existing server.

Secure Your Existing Data

Secure Data From Server

Let me tell you one thing, if you are porting your website to the different server then the biggest problem that you will face is the need to secure your data. I have read stories about how people destroyed their websites in the process of porting. You will have to pay special attention to this. Just plan ahead and keep patience, I repeat keep patience. Do not let excitement get you. I know dopamine levels in your brain gets high and fills you with excitement but do not hurry in this process. Backup all your data containing your files, images, database and all the other things that are there. My advice is to use reliable software for this process. In my case, I only had to port the images, documents and database, rest all my project files were synced with the Github. If you are new to development then I strongly suggest to learn Git and add this one skill to your resume. Follow the link to read about it… Github. In my case, I had to download about 400 MB of data, which I did with the help of Git. I created a new repository and pushed everything into it from my server. This facility may not be available for you if you are on a shared hosting, therefore, use FTP client. I prefer Filezilla. This way I backed up all the folders, files and images from the server.

I was using PhpMyAdmin for managing the database on the server. It was quite easy to export complete database with few clicks. Now, I successfully backed up my data and secured it. It took me about 2 hours. Now, the next thing was to set up the website on the new server. I didn’t make any changes to my existing website. Didn’t stopped it until I set up my website onto my new server. The next big problem that arises is maintaining your Google Page Rank. You do not want to make a bad impression in eyes of Google. Let’s see what I did to cope up with it.

Maintaining Google Page Rank

Preserve Google Page Rank

One of the most important phase in porting your website successfully. You must now take it lightly. One wrong move and all your hard work go in vain. The concept for preserving Google Page Rank is fairly simple. You just need to redirect your old pages to their new address with a status code of 301. You might have heard it somewhere about “301 Redirect” and if you are hearing it for the first time, well let’s say you do not spend much time reading.

What is 301 Redirect and why would you need it?

“301 Redirect” simply tells the web crawlers that the page current page has been shifted to their new location and then you provide the new location for the same. A real world analogy to this will go something like this, let’s say you moved to someplace to the outskirts of your city. Later, one of your friends came knocking doors at your old address. Now, imagine what would happen if no one will be there to address him. He won’t have any choice but to go back with a thought that he will never find you again. That is bad, Right? But what if you attached a note on your front door with your new address. That way he will know your current address and will move to your new house to meet. Same goes with the web crawlers, you must provide the new address for all the pages that has been moved.

It requires logics work it out. In my case, this was a little trickier because I had to move the website on the same domain without interfering with the WordPress page URLs. There was a fewer choice in front of me.

  • Copy Paste each blog with the same slug
    it seems a more intuitive solution but what if you have more than 40 articles to port. You cannot just copy paste each of the blogs. Yes, you can make a resolution to port 5 articles every day which would take around 8 days to port all your articles, but what if you have more than 80 articles. Then what are you going to do? On the top of that what if you are lazy. This becomes a really tiring and time-consuming thing at this time.
  • Find a way out depending on your website’s architecture
    I opted for this solution. I had to find a way to port my database completely without wasting my precious time and I found a really simple solution. I took my whole project and integrated it with the existing WordPress application and created a separated database to serve the data. It is like I’m running two different websites under the same domain. The old links will be served from a different database and all the new links will be served by WordPress database.

Pros and cons I faced with my later approach.

Pros –

  1. I didn’t have to do any heavy lifting
  2. This was a time-saving approach, I saved about 8 days with this approach
  3. There was near to no downtime

Cons –

  1. Complex redirect logic formulation
  2. Knowledge of the core functioning modules of both the Application
  3. Sooner or later you will have to change the old website layout to match the new one for better UX

Now, it is up to you to choose which a better solution is for you.

Redirection Logic

301 Redirect

It all comes down to the structure of your website. My old websites permalinks were displayed in this format, www.olderversion.com/site/blog/345/article-slug/, and the current version has permalinks in this format www.currentversion.com/article-slug/ you can see the distinction here. So, all I had to do was to parse the incoming URLs, pass them to pattern match and if pattern matches then redirect the URLs safely to their new home. This redirection is pretty simple and does not require any advance knowledge on the developers’ part. You could write a Redirect Rule in .htaccess and put it in the root of your project. Here, is the redirect logic for the same,

RewriteEngine on
RedirectRule ^site/blog/([0-9]+)/([a-zA-Z0-9-]+)/?$ HTTP://currentversion.com/project-folder/site/blog/$1/$2 [R=301,L]

This is it. It will match the incoming URLs pattern and redirect it their new home. Yeah, it’s simple but it did requires a redirect on the server part and though the performance affected is negligible, it is there. And too many redirects are not good. So, I didn’t opt for this solution. I simply changed the internal routeing pattern of the older website such that it will serve URLs in this fashion /blog/345/article-slug instead of /site/blog/345/article-slug. Then I simply changed the name of the project folder to site. So, automatically all the request will be mapped to their correct home. Plus there will be no redirection, therefore, saving the valuable server resource. If someone asks me about the performance lag in porting, I can say that there is no performance issue as everything is working the way it used to before. In fact, there are two different databases to serve different articles, which would instead improve the performance in times of heavy traffic. All that said, I recommend you to follow the redirection rule because it’s straightforward and less time consuming and you do not have to be an expert to do that. Copy paste the code and you are good to go J

Conclusion

Porting a website is really a few hours job given that you understand the architecture of your existing website and also the new platform that you are looking to port to. I know CodeIgniter and WordPress both very well, thus porting Codeignitor to WordPress was not that difficult. Hope you enjoyed the article and learned something from my experience. Just comment below if you face any problem or want to discuss more any phase of porting.

Cheers 🙂

Port Existing Website to WordPress

First of all, I would like to apologise to all my reader for any inconvenience caused during all the porting process. It wasn’t easy for me as I was doing something like this for the first time. I sure knew the basics theoretically but missing out on the practical knowledge. It took me about a week’s time to get it all up and running. And finally, when it’s finished, I could finally write my blogs again :). It requires a-lot to port your existing website to wordpress or some different platform.

In this article, I would like to share my practical knowledge which would help you in the future. Here’s the list of problems that you might face while porting your website to some other domain or to some other platform altogether, (just like in my case).

Port Existing Website to WordPress Requires –

  • Preserving Google Page Rank
  • Thorough Understanding of different types of redirects
  • Logic Formulation
  • Porting Database (if you are porting to another platform)
  • Minimum Website Downtime
  • Maintain a Good User Experience

The very first problem that was in front of me was the Google Ranking. You wouldn’t want to make Google sad, it may badly affect your website’s visibility. Hopefully, Google provides solutions for this problem. All you need to do is provide the new address for the moved pages to Google. This is really simple to do, all you need is to give a “301 redirect” to the new page address. If you are porting your existing website to some other domain, i.e, from www.example.com to www.differentexample.com then it becomes easier compared to the situation when you have to port your entire website to another platform or you may have to move your website to a new place inside your server. Both the situation have their pros and cons.

Porting to a different domain
The problems related to this situation are –

  • Page Redirects
  • Database Porting

Page Redirects

301 Redirect

You bought a new domain and hosted your new website there. Once your website is up and running, then you simply start redirecting your old website URLs to their new address without making any major changes to your website. You may have to come up with a redirection logic, which will solely depend on your project’s structure. Suppose, your old website blog URLs are shown in this format, www.oldwebsite.com/blog/123/port-website and your new website’s URLs format is www.newwebsite.com/port-website, then, in this case, you may use .htaccess file to redirect pages that match this particular pattern to their new home. You could simply write a redirect rule like the one below,

RewriteEngine on
RedirectRule ^blog/[0-9]+/([a-zA-Z0-9-]+)/?$ HTTP://www.newwebsite.com/$1 [R=301,L]

if you want to read more about redirection rules, you may follow this link, URL Rewriting for the fearful.

So, that was easy, Right? Now, you are left with the database porting part.

Database Porting

Port Database

Database porting is a tedious task, if you are porting the website to a similar platform like, from WordPress to WordPress then it may not cause you much trouble, but if you are porting to a whole different platform then you must look for some innovative ways to do that. You may search for some existing Softwares to make your job easy or you can walk the path I did. I’m running the old and new website together :D. I created a different database for my older website and simply imported the database there. I let my old website serve the way it was doing before and created a different database for WordPress. So, my website’s structure is pretty much the mixture of old and new.

One may ask about the performance factor for doing something like this, well, there’s not much difference in the performance because I haven’t tweaked with the core files. So basically, there are two different websites operating under the same domain. By-the-way you can take a look by yourself, here’s the link to my older website My Old Website, you may discuss more in the comments below.

Minimum Website Downtime

Another important thing to consider here is the downtime of your website. You may not want to make a bad impression for a new visitor. A returning visitor may know you and understand the downtime for a website but it will leave a bad impression on a new potential visitor. On top of this, it can also affect your Google Page Ranking. There are solutions to let google know that your website is under a temporary maintenance and that you can do with a “503 Status Code”. It simply states that the server is currently unable to handle the request due to a temporary overloading or maintenance of the server. You can also tell the crawlers about the retry time. You may use the below code snippet to return a 503 status code on your page.

header(‘HTTP/1.1 503 Service Temporarily Unavailable’);
header(‘Status: 503 Service Temporarily Unavailable’);
header(‘Retry-After: 300’);//300 seconds

Conclusion

By taking care of these simple steps, you can easily port your website to a new server or domain by keeping the integrity of your website intact. I learned these things by doing them practically and there will be lots of hidden traps that you might face, so my advice to you all is to plan ahead. This article was just an overview of all the problems that you might face, there are differents tastes to these problems as well. I will write another article about the problems I faced and what I did to solve them. I hope you had a great experience reading this article.

One Life, Rise and Shine

cheers 🙂