Compdigitec Labs

« | Home | »

Changing the user agent of PHP

By admin | August 20, 2008

If you ever need to adjust or change the default user agent that PHP accesses pages with (http and ftp wrappers) because either the default PHP user agent was blocked (“PHP”) or you wrote a bot with PHP and wish to customize it, you can do so easily with a php directive called “user_agent”. Note that 3rd party ways (such as cURL) are not affected by this setting.

To set it, you can use the following function:

<?php

function set_php_user_agent($useragent = ‘PHP’) {
$u = strval($useragent);
if(
ini_set(‘user_agent’,$u) === false) {
$r = false;
} else {
$r = true;
}
return
$r;
}

// Example:
set_php_user_agent(‘TestAgent/1.0 (http://www.example.com/testagent/)’);

?>

To get you started, here are some user agents for you to use or test:

If you found this article interesting or helpful, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more interesting articles!

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: Internet, PHP | 8 Comments »

8 Responses to “Changing the user agent of PHP”

  1. Nova88 Casino ทางเข้า คาสิโนสด Says:
    November 2nd, 2024 at 20:05

    … [Trackback]

    […] Find More Info here to that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

  2. ไก่ตัน Says:
    November 2nd, 2024 at 21:55

    … [Trackback]

    […] Read More on to that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

  3. รับจํานํารถ Says:
    November 2nd, 2024 at 21:56

    … [Trackback]

    […] Find More to that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

  4. รับซื้อกระเป๋าแบรนด์ Says:
    November 9th, 2024 at 04:27

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

  5. free cam tokens Says:
    November 11th, 2024 at 03:06

    … [Trackback]

    […] Here you will find 73080 more Info on that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

  6. オンラインカジノ Says:
    November 27th, 2024 at 05:12

    … [Trackback]

    […] Information on that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

  7. best diet Says:
    December 3rd, 2024 at 17:37

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

  8. live video Says:
    December 6th, 2024 at 13:54

    … [Trackback]

    […] Info to that Topic: compdigitec.com/labs/2008/08/20/changing-the-user-agent-of-php/ […]

Comments