ionicle Posted July 11, 2013 Share Posted July 11, 2013 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 More sharing options...
doddsey_65 Posted July 11, 2013 Share Posted July 11, 2013 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 Link to comment https://forums.phpfreaks.com/topic/280068-blocking-browser-agent-with-php/#findComment-1440320 Share on other sites More sharing options...
ionicle Posted July 11, 2013 Author Share Posted July 11, 2013 Geez, you're absolutely right... Silly me. Thank you! Link to comment https://forums.phpfreaks.com/topic/280068-blocking-browser-agent-with-php/#findComment-1440321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.