Short answer: NO.
Your code can examine the User-Agent header in the HTTP request and make some decisions based on the content, but that is not foolproof by any means. The HTTP requester (browser, spider, wGet, etc, etc) can build a User-Agent header containing whatever it wants, ans as an HTTP responder, your site has to take it on trust. Google or check Wikipedia
] for "User Agent Spoofing"