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 | 11 Comments »

11 Responses to “Changing the user agent of PHP”

  1. รีวิวเกมสล็อต ค่าย PG SLOT Says:
    March 27th, 2025 at 21:13

    … [Trackback]

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

  2. แทงบอลสด แบบเรียลไทม์ Says:
    April 8th, 2025 at 19:09

    … [Trackback]

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

  3. ไฟหน้ารถยนต์โปรเจคเตอร์ Says:
    April 11th, 2025 at 05:36

    … [Trackback]

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

  4. สล็อตเกาหลี Says:
    April 22nd, 2025 at 10:24

    … [Trackback]

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

  5. endolift Says:
    May 9th, 2025 at 21:51

    … [Trackback]

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

  6. บ้านพักคนชรา Says:
    May 14th, 2025 at 20:53

    … [Trackback]

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

  7. ufa777 Says:
    May 18th, 2025 at 20:51

    … [Trackback]

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

  8. serviços de redes informática Says:
    May 21st, 2025 at 13:50

    … [Trackback]

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

  9. Mト孕tskテゥ, obecnテュ テコナ兮dy Says:
    June 5th, 2025 at 07:26

    … [Trackback]

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

  10. จัดงานศพครบวงจร Says:
    June 9th, 2025 at 20:47

    … [Trackback]

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

  11. afrikaanse oorbellen Says:
    June 10th, 2025 at 12:37

    … [Trackback]

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

Comments