Reputation: 231
Is there any way to detect if the user is using a real browser?
I am able to get user agent string from $_SERVER['HTTP_USER_AGENT']
. But I am not sure if it was a real browser . Can we do anything at the php side to see if its real browser?
Upvotes: 0
Views: 93
Reputation: 3312
No, you cannot reliably detect if a request was sent be a "real browser". (Assuming with "real browser" you mean something as a chrome/firefox/safari installed on a standard consumer OS and not something like curl, an ajax call or a crawler etc.)
Thats because the user-agent is nothing but a http header field. You can easily fake it. E.g. sending the following request using curl would look on your server as if I used a regular Chrome 44 on a Mac:
curl -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" http://your-website.com
But apart from the fact that the user-agent header is not reliable: You can of course use the field to decide whether the request was issued by an "expected" client. In 99.9% of all requests you will find the "real" client in the user agent header. But you shouldn't make any security-sensitive functions dependent on it.
Upvotes: 1