0

Hello is there a way to detect a browser with javascript / php without checking a useragent? I'm trying to detect non-human visitors (sockets & CURL attempts) that might have faked a useragent.

3 Answers 3

1

Not reliably, no. Anyone can fake an actual client.

Well-behaved bots will use their own user-agent. You shouldn't concern yourself with non-well-behaved bots anyway.

Sign up to request clarification or add additional context in comments.

Comments

0

Agree that the user-agent is unreliable and easily spoofed. However, you might be able to build up some JavaScript to make spoofing a little harder. It certainly could differentiate things that don't have a JavaScript engine. See my answer here: https://stackoverflow.com/a/12571513/399704

Comments

0

There is more than trying to detect it with JavaScript or via user agent string.

I did some research on how the browser can be identified when faking the user agent string. I found out that many browsers (sometimes with little version differences, sometimes with big ones) send different header information in a different order. In general, it's possible to differentiate between all big browsers (Firefox, IE, Chrome, ...) by detecting the order the header information was sent to the server. Despite everything this can also be spoofed.

For more information read here: http://hide.network/why-does-changing-your-user-agent-almost-come-to-nothing/

It's a little bit tricky to detect, but possible. In PHP, you can simply use function getallheaders() to accomplish this task. As I tested, it gives you the same order of header information as the browser sends. You only need to detect the actual index of every key.

<?php foreach (getallheaders() as $name => $value) { echo "$name: $value<br />\n"; } ?> 

Edit:

I wrote a script to detect some main browsers in PHP. At first I forgot the referer that will be sent by clicking a link to the page. I added headers with referer of IE and FF to the list, maybe that can help with anything. I also uploaded the script to hide.network / header.php but can't post more than two links.

<?php $headerInformation = array(); // declaring and filling pre-defined header orders of browsers $browserInformation = array ( "browserNames" => array ( "Mozilla Firefox 37.0", "Mozilla Firefox 37.0 with referer", "Internet Explorer 11", "Internet Explorer 11 with referer", "Internet Explorer 8", "Google Chrome 42", "SRWare Iron 37" ), "headerInformation" => array ( array("host", "user-agent", "accept", "accept-language", "accept-encoding", "connection", "cache-control"), array("host", "user-agent", "accept", "accept-language", "accept-encoding", "referer", "connection", "cache-control"), array("accept", "accept-language", "user-agent", "accept-encoding", "host", "dnt", "connection"), array("accept", "referer", "accept-language", "user-agent", "accept-encoding", "host", "dnt", "connection"), array("accept", "accept-language", "user-agent", "accept-encoding", "host", "connection"), array("host", "connection", "cache-control", "accept", "user-agent", "accept-encoding", "accept-language"), array("host", "connection", "accept", "user-agent", "accept-encoding", "accept-language") ), "identScore" => array(0, 0, 0, 0, 0) ); // parsing all header values foreach (getallheaders() as $name => $value) { array_push($headerInformation, strtolower($name)); } // calculating possibility for each browser for($i = 0; $i < count(10); $i++) { for($j = 0; $j < count($browserInformation["browserNames"]); $j++) { $currentPossibility = count(array_intersect_assoc($browserInformation["headerInformation"][$j], $headerInformation)) / count($headerInformation) * 100; $currentPossibility = round($currentPossibility, 2); $browserInformation["identScore"][$j] = $currentPossibility; } } // sort array array_multisort($browserInformation["identScore"], SORT_DESC, SORT_NUMERIC, $browserInformation["browserNames"], $browserInformation["headerInformation"]); // output for($i = 0; $i < count(10); $i++) { for($j = 0; $j < count($browserInformation["browserNames"]); $j++) { echo "possibility " . $browserInformation["browserNames"][$j] . ": " . $browserInformation["identScore"][$j] . " %<br />"; } } // output original sent header echo "<pre>"; var_dump($headerInformation); echo "</pre>"; ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.