Jump to content

Blocking browser agent with PHP


Go to solution Solved by doddsey_65,

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

  • Solution
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.