检测:来自curl或浏览器

检测:来自curl或浏览器

问题描述:

I've got an almost empty page that I need for a curl. The thing is that it is also accessible by a browser and looks weird.

Is it possible in PHP to detect if the request come from a browser or a curl ? So that way I can make a redirect if it comes from browser.

Thank you.

我有一个几乎空的页面,我需要卷曲。 问题是它也可以访问 通过浏览器看起来很奇怪。 p>

PHP是否可以检测请求是来自浏览器还是卷曲? 因此,如果它来自浏览器,我可以进行重定向。 p>

谢谢。 p> div>

This will get you the client Agent, among other stuff. If your curl does not pretend to be something else, it should do.

foreach (getallheaders() as $name => $value) {
    echo "$name: $value
";
}

or simpler: $_SERVER['HTTP_USER_AGENT']

gets you the user-agent (browser signatur) directly.

Browser sends User-Agent header in request, if you don't setup User-Agent in curl just check request for this header.