Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Blocking browser agent with PHP

$
0
0

Hey guys, I am trying to figure out a quick and easy way of blocking a certain type of browser agent from accessing my page. I would like to only block a visitor if they use a specific browser agent, represented by a specific string, obtained via HTTP_USER_AGENT.

 

Here's the code itself:

 

 

$v_agent = $_SERVER['HTTP_USER_AGENT'];

 

if ($v_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)") {

die();

}

 

 

When I test it out, with the exact same browser agent bearing that string, it executes the die command, but when I test it with another agent, it blocks them too, despite the fact, that the second agent is a different one.

 

What am I missing here?


Viewing all articles
Browse latest Browse all 13200

Trending Articles