php语法如何设置User Agent字符串(简单示列)

2025年01月17日 建站教程

如何利用php语法设置User Agent字符串,下面web建站小编给大家举一个简单的示列!

示列如下:

$url = 'https://www.example.com';
$useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

本文链接:http://so.lmcjl.com/news/21508/

展开阅读全文
相关内容