5ubliminal@twitter

4Real or Fake - User Agent Disguise 4 PHP Coders : 5ubliminal's TellinYa

<a href="http://www.tellinya.com/art2/133/">4Real or Fake - User Agent Disguise 4 PHP Coders : 5ubliminal's TellinYa</a>
Must Reads: Web Scraping | Link Farming | Code Snippets | SEO Freeware » I'm on vacation! … still alive :)
Reveal More!

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.

Why would I change my user agent?

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.

How can I change my User-Agent?

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.

4 Comments Posted By Readers :

Add your comment
#1 Desloch from United States web
Posted on Monday, 09 June, 2008
Interesting ... unfortunately is not exactly what I need. I would like to change referer and not user agent. May this is exactly what I want to do.
In a page www.mysite.com/page1 I put a picture from another server. I want to be referer images www.mysite.com. I do not want to be as referer www.mysite.com/page1. What I do is similar to hotlinking but I want the admin server where they are hosted images to see as referer www.mysite.com. Do not want him to know that I bring to www.mysite.com/page1 images.
#2 5ubliminal web
Posted on Monday, 09 June, 2008
You can't unless you download the images and save them locally. The referer is a client-side feature and is sent by the browser so you have no control over it.
You gotta steal the images and serve them locally if you don't want to be caught.
#3 Desloch from United States
Posted on Monday, 09 June, 2008
Thanks for the quick response. Unfortunately, we can not copy images from his server for some reason. I'm thinking to bring the entire page with his picture on my page in the iframe. But all I need to hide referer. Is there a solution to the redirection but do not wish this method.
I think I use a frames. It seems it's the best method to hide referer. Cheers
#4 5ubliminal web
Posted on Monday, 09 June, 2008
I'm pretty sure you won't succeed using IFRAMES. Try it but I have no idea what referer they show. Make some tests first but for complete safety cache the images.
You choose between being a hotlinker or an art thief :)
Post Feedback 
Name *
Mail *
URL
« Anti-Spam
» URL will only go live after a review. Comments are moderated. «
5ubliminal's TellinYa.com SEM & SEO Blog © 2007 - All rights reserved unless mentioned otherwise .
Rendered On : [Thursday, 21 August, 2008 - 20:59:47 GMT]   No Ajax / Flash Used Here
" 4Real or Fake - User Agent Disguise 4 PHP Coders : 5ubliminal's TellinYa "