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

358 Responses to “Changing the user agent of PHP”

  1. เรียนพิเศษเชียงใหม่ Says:
    December 7th, 2025 at 16:03

    บทความมีประโยชน์มาก
    ช่วงนี้กำลังมองหา สอนพิเศษเชียงใหม่ ให้กับเด็กๆ

    มีหลายที่ในเชียงใหม่ให้เลือกเลย
    ขอบคุณสำหรับข้อมูลครับ!

    Feel free to visit my web blog :: เรียนพิเศษเชียงใหม่

  2. กวดวิชาเชียงใหม่ Says:
    December 7th, 2025 at 16:11

    รีวิวดีมากเลย

    ช่วงนี้กำลังมองหา เรียนพิเศษเชียงใหม่ ให้กับเด็กๆ
    มีหลายที่ในเชียงใหม่ให้เลือกเลย
    ขอบคุณสำหรับข้อมูลครับ!

    my website; กวดวิชาเชียงใหม่

  3. ร้านชาบู เชียงใหม่ Says:
    December 7th, 2025 at 23:57

    บทความดีมากเลยครับ
    กำลังหา ร้านบุฟเฟ่ต์ชาบูเชียงใหม่ อยู่พอดี
    กำลังรวบรวมร้านไว้ลองกิน

    ขอบคุณสำหรับข้อมูลครับ!

    Look at my web page :: ร้านชาบู เชียงใหม่

  4. supercar tuning Says:
    December 7th, 2025 at 23:57

    ข้อมูลดีมากครับ โดยเฉพาะเรื่อง แต่งซุปเปอร์คาร์

    ผมเองก็ใช้อู่ อู่เฉพาะทางซุปเปอร์คาร์ อยู่เหมือนกัน งานเขา ละเอียด จริงๆ
    ใครมีรถซุปเปอร์คาร์ลองดูบริการแนวนี้ได้เลยครับ

    My web blog supercar tuning

  5. ร้านชาบู เชียงใหม่ Says:
    December 8th, 2025 at 00:04

    อ่านแล้วหิวเลย
    กำลังหา ร้านชาบู เชียงใหม่ อยู่พอดี
    ใครมีร้านแนะนำบอกกันได้เลย
    ขอบคุณสำหรับข้อมูลครับ!

  6. อู่ซ่อมรถซุปเปอร์คาร์ Says:
    December 8th, 2025 at 01:05

    เป็นประโยชน์สุดๆ โดยเฉพาะเรื่อง supercar tuning
    ผมเองก็ใช้อู่ อู่เฉพาะทางซุปเปอร์คาร์ อยู่เหมือนกัน งานเขา ละเอียด จริงๆ

    ใครมีรถซุปเปอร์คาร์ลองดูบริการแนวนี้ได้เลยครับ

    Check out myy website: อู่ซ่อมรถซุปเปอร์คาร์

  7. supercar tuning Says:
    December 8th, 2025 at 01:08

    ข้อมูลดีมากครับ โดยเฉพาะเรื่อง
    แต่งซุปเปอร์คาร์
    ผมเองก็ใช้อู่ อู่ซ่อมรถซุปเปอร์คาร์ อยู่เหมือนกัน งานเขา ละเอียดจริงๆ

    ใครมีรถซุปเปอร์คาร์ลองดูบริการแนวนี้ได้เลยครับ

    Alsso visit my page :: supercar tuning

  8. ชาบูเชียงใหม่ Says:
    December 8th, 2025 at 01:35

    อ่านแล้วหิวเลย
    กำลังหา ร้านชาบู เชียงใหม่ อยู่พอดี

    ช่วงนี้อยากกินชาบูมากๆ
    ขอบคุณสำหรับข้อมูลครับ!

    Here is my web page – ชาบูเชียงใหม่

Comments