If you use $ _SERVER ['HTTP_USER_AGENT'], this means that you want to put a test on each page. Type:
$a = $_SERVER['HTTP_USER_AGENT'];
if ($a == motor de busca)
{
// Vamos sair daqui
}
// se chegamos aqui, e porque nao e um motor de busca, então podemos continuar
The difficulty and the test. You have 2 options:
You only want to authorize one type of browser. For example, you
want to be the only one to have access. In this case, you will take the test
type: if the HTTP_USER_AGENT = my browser, fine, if not bye bye!
Easy because you know the HTTP of your browser.
You want to ban access to the engines. But in this case you need
know the HTTP_USER_AGENT of the engines ... I think it's impossible because
has a lot and has no rule about it.
For example here are the HTTP_USER_AGENT of 4 "bots" (search engine).
Mozilla / 5.0 (compatible; Baiduspider / 2.0; + link )
Mozilla / 5.0 (compatible; Exabot / 3.0; + link )
msnbot-media / 1.1 (+ link )
TurnitinBot / 3.0 ( link )
They are very different from each other, and to check in PHP that they are search engine, I find it very complicated.
You need to find another option.
One question: what is the goal really? Safety? Privatity?