This has been slightly covered in the php and curl class and the code found here relies on the class metioned there. Here it goes …
I'm not going to explain the concept of user agent here but I might do it pretty soon. If you consider necessary explictily request this through comment form.
Even if this is not every-day practice there are many moments when user-agent can / should be changed. User agents allow people to associate visitors with software used to load the site. So if you show a different ID you might be treated differently.
Different treatment should not occur according to search engines. What a search engine sees is also what you see! Or is it not …
A fake User Agent is the basic way to verify if websites show you what they show search engines crawlers. I said basic as this can be done in advanced ways by using robot detection and verification.
This can also be used in Link Exchange to check if the page where you are supposed to get a link from really has a link as search engines sees it.
Or you can use this trick to verify if your cloaking is working properly ;). User Agent cloaking is by far the lamest method of cloaking (suicidal if you ask me! Check previously mentioned method of bot verification to do it slightly better) so do not use it except for legit porpouses that won't get you banned. I'll mention them in the near future.
I will show you the 4 lines of PHP code that will do the trick and will get the web page requested pretending to be googlebot by changing user agent.
<?
// Initiate the eHttpClient
$httpClient = new eHttpClient();
// Assign new user-agent! gg,ms,yh are hard-coded
// in the script so you don't need to know them!
// Change gg to any other to set that one.
$httpClient->setUserAgent("gg");
// Get the HTML of the page.
$htmlPage = $httpClient->get($url);
// Get the HTTP headers
$httpHeaders = $httpClient->getHeaders();
// Play with content and headers! $htmlPage & $httpHeaders
?>
As I mentioned gg stands for googlebot user agent, ms stands for msnbot user agent and yh stands for yahoo! slurp user agent. Any other user agent string is set exactly as you write it as parameter.
Post Feedback