Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bansal's avatar

Get curl CURLOPT_USERAGENT

how to get curl CURLOPT_USERAGENT in controller

0 likes
2 replies
bobbybouwmann's avatar

You don't have to use curl since Laravel has the information as well for you. You can for example use

// In your controller
public function index(Request $request)
{
    $request->header('User-Agent');

}

You can also access this information somewhere else using the request helper or facade

request()->header('User-Agent');
Request::header('User-Agent');
bansal's avatar

that is only case when we pass header like

curl_setopt($this->process, CURLOPT_HTTPHEADER,$headers);

But if we pass user agent like

curl_setopt($this->process, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

then what??

Please or to participate in this conversation.