Jump to content

Blocking browser agent with PHP


ionicle

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/280068-blocking-browser-agent-with-php/
Share on other sites

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)")

You were missing another = sign in the condition statement

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.