How do I detect what browser is used to access my site? - http

How do I detect what browser (IE, Firefox, Opera) the user is accessing my site with? Examples in Javascript, PHP, ASP, Python, JSP, and any others you can think of would be helpful. Is there a language agnostic way to get this information?

If it's for handling the request, look at the User-Agent header on the incoming request.
UPDATE: If it's for reporting, configure your web server to log the User-Agent in the access logs, then run a log analysis tool, e.g., AWStats.
UPDATE 2: FYI, it's usually (not always, usually) a bad idea to change the way you're handling a request based on the User-Agent.

Comprehensive list of User Agent Strings from various Browsers
The list is really large :)

You would take a look at the User-Agent that they are sending. Note that you can send whatever agent you want, so that's not 100% foolproof, but most people don't change it unless there's a specific reason to.

A quick and dirty java servlet example
private String getBrowserName(HttpServletRequest request) {
// get the user Agent from request header
String userAgent = request.getHeader(Constants.BROWSER_USER_AGENT);
String BrowesrName = "";
//check for Internet Explorer
if (userAgent.indexOf("MSIE") > -1) {
BrowesrName = Constants.BROWSER_NAME_IE;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_FIREFOX) > -1) {
BrowesrName = Constants.BROWSER_NAME_MOZILLA_FIREFOX;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_OPERA) > -1) {
BrowesrName = Constants.BROWSER_NAME_OPERA;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_SAFARI) > -1) {
BrowesrName = Constants.BROWSER_NAME_SAFARI;
} else if (userAgent.indexOf(Constants.BROWSER_NAME_NETSCAPE) > -1) {
BrowesrName = Constants.BROWSER_NAME_NETSCAPE;
} else {
BrowesrName = "Undefined Browser";
}
//return the browser name
return BrowesrName;
}

You can use the HttpBrowserCapabilities Class in ASP.NET. Here is a sample from this link
private void Button1_Click(object sender, System.EventArgs e)
{
HttpBrowserCapabilities bc;
string s;
bc = Request.Browser;
s= "Browser Capabilities" + "\n";
s += "Type = " + bc.Type + "\n";
s += "Name = " + bc.Browser + "\n";
s += "Version = " + bc.Version + "\n";
s += "Major Version = " + bc.MajorVersion + "\n";
s += "Minor Version = " + bc.MinorVersion + "\n";
s += "Platform = " + bc.Platform + "\n";
s += "Is Beta = " + bc.Beta + "\n";
s += "Is Crawler = " + bc.Crawler + "\n";
s += "Is AOL = " + bc.AOL + "\n";
s += "Is Win16 = " + bc.Win16 + "\n";
s += "Is Win32 = " + bc.Win32 + "\n";
s += "Supports Frames = " + bc.Frames + "\n";
s += "Supports Tables = " + bc.Tables + "\n";
s += "Supports Cookies = " + bc.Cookies + "\n";
s += "Supports VB Script = " + bc.VBScript + "\n";
s += "Supports JavaScript = " + bc.JavaScript + "\n";
s += "Supports Java Applets = " + bc.JavaApplets + "\n";
s += "Supports ActiveX Controls = " + bc.ActiveXControls + "\n";
TextBox1.Text = s;
}

PHP's predefined superglobal array $_SERVER contains a key "HTTP_USER_AGENT", which contains the value of the User-Agent header as sent in the HTTP request. Remember that this is user-provided data and is not to be trusted. Few users alter their user-agent string, but it does happen from time to time.

On the client side, you can do this in Javascript using the navigation.userAgent object. Here's a crude example:
if (navigator.userAgent.indexOf("MSIE") > -1)
{
alert("Internet Explorer!");
}
else if (navigator.userAgent.indexOf("Firefox") > -1)
{
alert("Firefox!");
}
A more detailed and comprehensive example can be found here: http://www.quirksmode.org/js/detect.html
Note that if you're doing the browser detection for the sake of Javascript compatibility, it's usually better to simply use object detection or a try/catch block, lest some version you didn't think of slip through the cracks of your script.
For example, instead of doing this...
if(navigator.userAgent.indexOf("MSIE 6") > -1)
{
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
objXMLHttp = new XMLHttpRequest();
}
...this is better:
if(window.XMLHttpRequest) // Works in Firefox, Opera, and Safari, maybe latest IE?
{
objXMLHttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) // If the above fails, try the MSIE 6 method
{
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

It may be dependent of your setting. With apache on linux, its written in the access log /var/log/apache2/access_log

You can do this by:
- looking at the web server log, OR
- looking at the User-Agent field in the HTML request (which is a plain text stream) before processing it.

First of all, I'd like to note, that it is best to avoid patching against specific web-browsers, unless as a last result -try to achieve cross-browser compatibility instead using standard-compliant HTML/CSS/JS (yes, javascript does have a common denominator subset, which works across all major browsers).
With that said, the user-agent tag from the HTTP request header contains the client's (claimed) browser. Although this has become a real mess due to people working against specific browser, and not the specification, so determining the real browser can be a little tricky.
Match against this:
contains browser
Firefox -> Firefox
MSIE -> Internet Explorer
Opera -> Opera (one of the few browsers, which don't pretend to be Mozilla :) )
Most of the agents containing the words "bot", or "crawler" are usually bots (so you can omit it from logs / etc)

check out browsecap.ini. The linked site has files for multiple scripting languages. The browsecap not only identifies the user-agent but also has info about the browser's CSS support, JS support, OS, if its a mobile browser etc.
cruise over to this page to see an example of what info the browsecap.ini can tell you about your current browser.

Related

Extract depthmap from Google Street View

Many posts such as this one use the REST API of Google Street View like this:
http://maps.google.com/cbk?output=xml&ll=40.7625000,-73.9741670&dm=1
However, this API does not work sometimes.
Google Street View seems does not rely on that REST API, and it may store the depthmap in this meta-file:
https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=us&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2sus!3m3!1m2!1e2!2sG2__WfQLZTzrsr7FP1wUyQ!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3
But I do not know how to extract depthmap from it. The method using Base64 in this post of Convert depth map (base64) of google street view to image does not work because the encoded string are very different.
Could anyone can get me some ideas? Thanks very much!
Here are some Python code lines to get the meta-file from Google Street View:
def getPanoJS_frm_lonlat(lon, lat):
url = "https://maps.googleapis.com/maps/api/js/GeoPhotoService.SingleImageSearch?pb=!1m5!1sapiv3!5sUS!11m2!1m1!1b0!2m4!1m2!3d{0:}!4d{1:}!2d50!3m10!2m2!1sen!2sGB!9m1!1e2!11m4!1m3!1e2!2b1!3e2!4m10!1e1!1e2!1e3!1e4!1e8!1e6!5m1!1e2!6m1!1e2&callback=_xdc_._v2mub5"
url = url.format(lat, lon)
return requests.get(url, proxies=None)
lon = -74.2249174
lat = 40.7040015
resp = getPanoJS_frm_lonlat(lon, lat)
line = resp.text.replace("/**/_xdc_._v2mub5 && _xdc_._v2mub5( ", "")[:-2]
# print(line)
jdata = json.loads(line)
print("This part may be the depthmap:")
print(jdata[1][5][0][5][3][2])
A part of the encoded depthmap in the metafile(not quite sure, and the entire string is too long to post here, please using the code above the download the meta-file):
Q0RrQUFBSUFBUWdCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUURUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJB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iUVRGcVBNS1dIZVpCb2ZZOXdpQmFRRUowNTBIQ0Jud1pRcDV6UU1MNml0Q18wWWFjd3V6RG5FSTNFd25EZUNZc1FlODhQTUl1dThDX2tFLUt3dTF4RDhETVBzUEM0aGhCd241Z0lrSThfSG9fOTRRMFFwOExKa0ZoZUI1QzE3OTN3T3VORkVMSEQ1akJRZnM2d2c=
I recently came across this problem too and I decided to dig into it with the help of a friend.
I found the GSVPanoDepth.js library that hadn't been updated in a while but still had the fundamentals of decoding the data and parsing it. It was all pretty much the same except the url has changed and the structure of the data a bit too. I forked the repo and updated it to work with the new url and structure - https://github.com/sidequestlegend/GSVPanoDepth.js
// This url no longer works
// url = "http://maps.google.com/cbk?output=json&cb_client=maps_sv&v=4&dm=1&pm=1&ph=1&hl=en&panoid=" + panoId;
url = "https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=uk&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2suk!3m3!1m2!1e2!2s" +
panoId +
"!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3"
fetch(url)
.then(res=>res.text())
.then(res=>JSON.parse(res.substr(4)))
.then(res=>res[1][0][5][0][5][1][2])
.then(res=>{
console.log(res);
return res;
})
.then(dm => {
var decoded, depthMap;
try {
decoded = self.decode(dm);
depthMap = self.parse(decoded);
} catch(e) {
console.error("Error loading depth map for pano " + panoId + "\n" + e.message + "\nAt " + e.filename + "(" + e.lineNumber + ")");
depthMap = self.createEmptyDepthMap();
}
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
})
.catch(e=>{
console.error("Request failed: " + url + "\n" + e);
var depthMap = self.createEmptyDepthMap();
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
});

JSoup - how does HTML structure affect response?

Trying to learn JSoup but having problems with response that may be due to structure issues (or stupidity, you tell me!). I do a simple query for "a[href]" but it only finds a subset 13 (text search tells me there are 162!). Why does it not find all?
Document doc = Jsoup.connect(J_URL).get();
String srchCSS = "a[href]";
Elements select = doc.select(srchCSS);
Iterator<Element> iterator = select.iterator();
Log.w(TAG, "'" + srchCSS + "' # " + select.size());
while (iterator.hasNext()) {
Element x = iterator.next();
System.out.println("'" + srchCSS + "': " + x.text());
}
Log.e(TAG, "%%% COMPLETE %%%");
I want to get the text from 'p' (see RED arrow). The a[href] above it is NOT being found?!?

how to compare asp.net radio button list values

I am trying to fix a search tool for work. This is the first time I have encountered ASP.NET. The current search tool has a radio Button list with three options of how to search our local directory. However the person that worked on this project before me did not finish the code and has since quit. The radio buttons as they are not do not affect the search query as I have noticed that no matter what option you pick the query is the same.
This is my attempt to rewrite the search function to incorporate the three radio button options. However when I incorporate this function into the rest of the code the page does not render at all and I am not getting the error. I dont think I made an error in the query strings because I took the original one and made variations of it by omitting Contains statements. I'm assuming the error comes from my if statements or how I am trying to compare the asp.net RadioButtonList ListItem values.
protected void btnclick_WorkspaceSearch(object sender, EventArgs e){
string strSearchTerm=tbSearch.Text.Trim()
if (rblSearchOption.SelectedValue == "all"){
// Find the search term in either a file name or file content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "OR CONTAINS(Contents, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue=="names"){
// Find the search term in a file name
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue =="contents") {
// Find the search term in a file's content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
searchIndex(indexQuery);
lit_strQueryString.Text = indexQuery;
}
I figured out the problem. For those that commented thank you for your input I did make some necessary changes to help correct potential errors. As for the original question to compare listItem values the line that I used was :
if (rblSearchOption.SelectedItem.Value =="contents"){
//logic here
}
i had tried this before but it did not work. I'm assuming because of the errors pointed out in the comments.
Additional Notes(based on the comments):
The code above has a missing ; in line1
string index query should be declared and initiated outside of the if statements.
Once again thank you to those who attempted to help me.
Glad you found your problem, a bit unrelated but looking at your code I would say it needs some serious refactoring. This code can be simplified by:
1) Using a switch statement.This will help evaluating the selected value of the radio button list just once unlike your code
2) Using a StringBuilder to construct the query
3) Removing repetition - the append logic for names and contents is exactly the same you can remove the repetition by using two case expression and providing one statement to execute.
System.Text.StringBuilder indexQuery = new System.Text.StringBuilder();
indexQuery.Append("SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank FROM Workspace..SCOPE() WHERE ");
switch(rblSearchOption.SelectedItem.Value)
{
case "all":
indexQuery.AppendFormat("CONTAINS(FileName,'{0}') ",strSearchTerm);
indexQuery.AppendFormat("OR CONTAINS(Contents,'{0}')",strSearchTerm);
indexQuery.AppendLine("ORDER BY Rank DESC");
break;
case "names":
case "contents":
indexQuery.AppendFormat("CONTAINS(FileName,'{0}')",strSearchTerm);
indexQuery.Append("ORDER BY Rank DESC");
break;
}
searchIndex(indexQuery.ToString());
lit_strQueryString.Text = indexQuery;

Asp.net paging crashing on chrome

I have a timer control on my page and an image handler which is set on every timer refresh. After about two minutes of running my page the page crashes on chrome with the "Aw Snap message". Can anybody help me out ??
JS Code.
var t
function set_coordinates_up(event) {
//Get final co-ordinates
var pos_x = event.offsetX ? (event.offsetX) : event.pageX - document.getElementById("divCar").offsetLeft;
var pos_y = event.offsetY ? (event.offsetY) : event.pageY - document.getElementById("divCar").offsetTop;
var hdf = document.getElementById('HiddenField1')
//Store event information in hidden feild
if (hdf != null) hdf.value = t + " " + pos_x + " " + pos_y;
}
function set_coordinates_down(event) {
//Get initial co-ordinates
var pos_x = event.offsetX ? (event.offsetX) : event.pageX - document.getElementById("divCar").offsetLeft;
var pos_y = event.offsetY ? (event.offsetY) : event.pageY - document.getElementById("divCar").offsetTop;
t = pos_x + " " + pos_y
}
check if your tab is leaking memory for some reason by opening up Chromes Task manager... probable reasons would be an infinite loop somewhere.
Chrome pages usually crash (Snap!) when there is low memory on the system. I would worry about that too.. Make sure you dont have many other processes running either.
Keep us updated.

How to check for the existence of an IIS 7 web site via WiX 3.5?

Note: This question can also be found on the WiX mailing list.
I need to be able to check for the existence of an IIS7 website based on the website's description. If the website does not exist I need to cancel the installation. If the website exists I want to continue the installation. I also need to be able to save the site id of the website so that I may use it during an uninstall.
For debugging purposes I have hard coded the website's description. I do not see any indication that a check for the website is being made within the MSI log file. This is the code I am using:
<iis:WebSite Id="IISWEBSITE" Description="Default Web Site" SiteId="*">
<iis:WebAddress Id="IisWebAddress" Port="1"/>
</iis:WebSite>
<Condition Message="Website [IISWEBSITE] not found.">
<![CDATA[IISWEBSITE]]>
</Condition>
Using ORCA I can see that IIsWebAddress and IIsWebSite tables are added to the MSI. The values are:
IIsWebsite
WEB: IISWEBSITE
Description: Default Web Site
KeyAddress: IisWebAddress
Id: -1
IIsWebAddress
Address: IisWebAddress
Web_: IISWEBSITE
Port: 1
Secure: 0
With the above code, the installation is halted with the error message "Website not found". It appears that IISWEBSITE is never getting set. Though, I know that "Default Web Site" exists. I know that I must be missing something, but what?
How can I perform a simple check for the existence of a website in IIS 7?
I too had same problem.
I wrote a custom action to check the version of IIS from registry.
On the basis of registry value create virtual directory
I wrote a custom action in Javascript to do this. If you are assuming IIS7, then you can use the appcmd.exe tool, and just invoke it from within Javascript to get the list of sites. In theory, it's pretty simple to do. But in practice, there's a bunch of hoops you need to jump through.
Here's what I came up with:
function RunAppCmd(command, deleteOutput) {
var shell = new ActiveXObject("WScript.Shell"),
fso = new ActiveXObject("Scripting.FileSystemObject"),
tmpdir = fso.GetSpecialFolder(SpecialFolders.TemporaryFolder),
tmpFileName = fso.BuildPath(tmpdir, fso.GetTempName()),
windir = fso.GetSpecialFolder(SpecialFolders.WindowsFolder),
appcmd = fso.BuildPath(windir,"system32\\inetsrv\\appcmd.exe") + " " + command,
rc;
deleteOutput = deleteOutput || false;
LogMessage("shell.Run("+appcmd+")");
// use cmd.exe to redirect the output
rc = shell.Run("%comspec% /c " + appcmd + "> " + tmpFileName, WindowStyle.Hidden, true);
LogMessage("shell.Run rc = " + rc);
if (deleteOutput) {
fso.DeleteFile(tmpFileName);
}
return {
rc : rc,
outputfile : (deleteOutput) ? null : tmpFileName
};
}
// GetWebSites_Appcmd()
//
// Gets website info using Appcmd.exe, only on IIS7+ .
//
// The return value is an array of JS objects, one per site.
//
function GetWebSites_Appcmd() {
var r, fso, textStream, sites, oneLine, record,
ParseOneLine = function(oneLine) {
// split the string: capture quoted strings, or a string surrounded
// by parens, or lastly, tokens separated by spaces,
var tokens = oneLine.match(/"[^"]+"|\(.+\)|[^ ]+/g),
// split the 3rd string: it is a set of properties separated by colons
props = tokens[2].slice(1,-1),
t2 = props.match(/\w+:.+?(?=,\w+:|$)/g),
bindingsString = t2[1],
ix1 = bindingsString.indexOf(':'),
t3 = bindingsString.substring(ix1+1).split(','),
L1 = t3.length,
bindings = {}, i, split, obj, p2;
for (i=0; i<L1; i++) {
split = t3[i].split('/');
obj = {};
if (split[0] == "net.tcp") {
p2 = split[1].split(':');
obj.port = p2[0];
}
else if (split[0] == "net.pipe") {
p2 = split[1].split(':');
obj.other = p2[0];
}
else if (split[0] == "http") {
p2 = split[1].split(':');
obj.ip = p2[0];
if (p2[1]) {
obj.port = p2[1];
}
obj.hostname = "";
}
else {
p2 = split[1].split(':');
obj.hostname = p2[0];
if (p2[1]) {
obj.port = p2[1];
}
}
bindings[split[0]] = obj;
}
// return the object describing the website
return {
id : t2[0].split(':')[1],
name : "W3SVC/" + t2[0].split(':')[1],
description : tokens[1].slice(1,-1),
bindings : bindings,
state : t2[2].split(':')[1] // started or not
};
};
LogMessage("GetWebSites_Appcmd() ENTER");
r = RunAppCmd("list sites");
if (r.rc !== 0) {
// 0x80004005 == E_FAIL
throw new Exception("ApplicationException", "exec appcmd.exe returned nonzero rc ("+r.rc+")", 0x80004005);
}
fso = new ActiveXObject("Scripting.FileSystemObject");
textStream = fso.OpenTextFile(r.outputfile, OpenMode.ForReading);
sites = [];
// Read from the file and parse the results.
while (!textStream.AtEndOfStream) {
oneLine = textStream.ReadLine();
record = ParseOneLine(oneLine);
LogMessage(" site: " + record.name);
sites.push(record);
}
textStream.Close();
fso.DeleteFile(r.outputfile);
LogMessage("GetWebSites_Appcmd() EXIT");
return sites;
}

Resources