One of the best ways to get your content discovered on the web is through search engines.
A search engine crawler requests as many pages as possible, and as allowed by the robots.txt configuration file.
The crawled pages are then categorised based on their contents.
Because web traffic drives ad revenue, an industry has popped up called search engine optimisation or SEO.
SEO draws more traffic and thus more ad revenue.
Most of the SEO techniques end up actually benefitting or at least being neutral to the end users experience.
For example, serving content over HTTPS is an SEO tool.
This helps to drive encryption around the web and increases user privacy and security.
Unfortunately, there are also some black hat SEO techniques.
These arent related to computer security black hats, as in bad guy hackers.
They do, however, exploit how the system works to their own advantage.
One of these tricks is called cloaking.
Its also expected that a search engine has the same experience.
A search engine can only prioritise results based on the content that it sees.
Cloaking is the black hat SEO technique of changing the content that the search engine sees.
An SEO-optimised page is shown to a search engine so that achieve a high relevancy ranking.
Actual human visitors, however, get served different content.
Spamdexing
Unfortunately, its typically used as a form of spamdexing and black hat SEO.
When a user visits they dont see the same thing at all.
Often they can be redirected to different content that isnt actually relevant.
Tip: Spamdexing is a portmanteau of Spam and Indexing.
It refers to an array of methods to illegitimately improve search engine ranking.
Of course, the users experience doesnt matter to the site owner.
Once the user hits their site and is served with ads, the owner is already generating ad revenue.
Conclusion
Cloaking is a form of black hat SEO.
It involves identifying requests coming from search engine crawlers and then serving them heavily SEO-optimised pages.
These pages are completely distinct from the content that is served to human users.