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

907 Responses to “Changing the user agent of PHP”

  1. บริการจัดดอกไม้งานศพ Says:
    March 23rd, 2026 at 19:34

    เนื้อหามีประโยชน์มาก
    ทำให้เข้าใจเรื่องพวงหรีดได้ลึกซึ้ง

    Also visit my site บริการจัดดอกไม้งานศพ

  2. บริการจัดดอกไม้งานศพ Says:
    March 23rd, 2026 at 19:35

    บทความนี้มีประโยชน์ ช่วยให้เลือกรูปแบบพวงหรีดได้ตรงตามความต้องการ

    my web page – บริการจัดดอกไม้งานศพ

  3. ร้านขายพวงหรีดดอกไม้สด Says:
    March 23rd, 2026 at 19:41

    เนื้อหาให้ความรู้มาก ทำให้เข้าใจเรื่องการเลือกพวงหรีดได้ชัดเจน

    my web page – ร้านขายพวงหรีดดอกไม้สด

  4. ร้านขายพวงหรีดดอกไม้สด Says:
    March 23rd, 2026 at 19:47

    เนื้อหามีประโยชน์มาก ทำให้เข้าใจเรื่องการเลือกพวงหรีดได้ลึกซึ้ง

    Also visit myy blog post; ร้านขายพวงหรีดดอกไม้สด

  5. ร้านส่งพวงหรีด Says:
    March 23rd, 2026 at 20:03

    ขอบคุณที่แบ่งปันเคล็ดลับการจัดพวงหรีดดอกไม้สด ครบถ้วน ดีต่อคนที่กำลังมองหาไอเดีย

    Have a look at my web blog: ร้านส่งพวงหรีด

  6. ขายพวงหรีด Says:
    March 23rd, 2026 at 20:21

    เป็นบทความที่อ่านแล้วได้ไอเดียวิธีเลือกพวงหรีดดอกไม้ เหมาะสมกับงานจริงๆ

    Review my web blog: ขายพวงหรีด

  7. ขายพวงหรีด Says:
    March 23rd, 2026 at 20:28

    เนื้อหาให้ความรู้มาก ทำให้เข้าใจเรื่องพวงหรีดได้ลึกซึ้ง

    Also visit my website ขายพวงหรีด

Comments