Saturday, October 3, 2009

Changing Default User Agent String Using PHP

It's easy to change the default user agent string of your php script (web server). Just use this piece of code in your crawler/scrapper script.

ini_set("user_agent","TechBongo Crawler V1.0");

If you want to test this piece of PHP code, write the following PHP code in a PHP file and execute the file. Now check the visitor log of the web page and you'll see your custom user agent string there, instead of the default user agent string.

ini_set("user_agent","Your User Agent String");

$data = file_get_contents("",0);

Print strip_tags($data,"");


No comments: