I need help... again: How can I get some general userinformation?

They have: 133 posts

Joined: Sep 2000

Hi all

I am back, to ansver a silly, probably fast ansvered question... I actually tried another forum on the web, bt since they didnt have the ansver, I had to disturb you again Shocked

My questions are simple:

I am making an ASP-scipt, that will get a lot of information regarding the user. The following, are the questions that I have:

1: I need to know, how I can get the users resolution

2: How do I get the users colordepth

3: How can I determain, what country the user comes from? (and can I?)

4: How do I determain what date the user has, when he visits the page.

5: And if possible, what OS the user is using (win 9x, or linus, mac'os xx etc...)

Thats it! I do not suppose that this should be hard... I hope that you can help me. (as you did many times before:p)

Kind regards
Casper Bang

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

hotcut,

1. The resolution has to be done on client, best to use JavaScript and use the screen.width & screen.height methods.

2. This also has to be done on the client it also uses the screen object, screen.colorDepth.

3. This information gets saved to the IIS logs (if enabled) but is not always reliable, and is most times blank.

4. You will have to detect the date on client side and then pass it to server.

5. This also get's saved to IIS logs (if enabled) and is also not always reliable.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

Hi

Thats sounds like the same ansver, that I got in the other forum...

Ok, Lets say that I have put all the data into a javascript variable, can I somehow put that variable, in an ASP variable, without needing to change the page?
As I said, it is a counter, so therefor it would be good, if I could just get the info with javascript, and then afterwards make ASP grab the data, and work with them...

Can you help me on this?

Casper

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Since ASP is a server side technology there is no way you can pass a client-side variable (JavaScript) to a server-side variable without changing the current page (ASP).

Probably the best way to setup what you want to do is to have a quick "detect" page that is almost invisible to the user. This page detects all your variables, then passes them to ASP via hidden text boxes, then that ASP stores those values and returns the user to the start page, as long as your server is fast this would almost be transparent to them.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

Thanks Peter

I was a kind of affraid, that I had to do that... But, well... I will do like that then... Would be nice though, if the other was posible Wink

Kind regards

Casper

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

this really isn't such a bad solution. I've used it before at work, and the users can't even tell that it has happened.
Check the code... I'm just making this up really quick.

<html><body>
<form name="myVars" action="your.asp" method=POST>
&lt;script language=javascript&gt;
<!--
// print the vars you want
document.write "<input type=hidden name=screen_width value='"+screen.width+"'>";
document.write "<input type=hidden name=screen_height value='"+screen.height+"'>";
document.write "<input type=hidden name=screen_color value='"+screen.colorDepth+"'>";
//so on and so forth

// now submit them!
myVars.submit();
-->
&lt;/script&gt;
</for>
</body></html>
'

I never new about colorDepth. Live And Learn!

Quick 'Qs'...
I'm reading (from an ASP book) that 'DATE_LOCAL' will return the 'local time zone'. IS that on the server or client?

Apache has a var 'HTTP_USER_AGENT', and a request var 'User-Agent', both return this for me: 'Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)'. If you can get something like this with IIS, you could use inStr(1,browserVar, "Windows") to get a true/false.

Anyway, good luck!

Mark Hensler
If there is no answer on Google, then there is no question.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Max,

Thanks for reminding me about HTTP_USER_AGENT, I use it all the time but I forgot that it also reports the user's OS (if it can). Regarding DATE_LOCAL, it doesn't seem to return any values for me (blank), I've tried using it as a server variable and a local variable with no luck.

Hotcut,

This code:

Request.ServerVariables("HTTP_USER_AGENT")

will return the users browser and OS you will just have to parse it.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

They have: 133 posts

Joined: Sep 2000

Once again, it was you two guys, Mwx and Peter that helped me out my problem Smiling

I think that I can use the code you gave me, to set up a good statistics counter... Thanks for that...

Just 1 little question:

You said that the line:
Request.ServerVariables("HTTP_USER_AGENT")

should return the users browser, and OS, but how do I then split it up, so that it will give me each of that information, in seperate variables... That would make it easyer to manage in a database, if I could that...
That was probably just a silly question, but Iam sure that you can ansver the question A ZAP Wink

Many thanks
Casper

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

hotcut,

The following code should work:

<?php
    UserAgent
= Request.ServerVariables("HTTP_USER_AGENT")
   
   
UserAgentLength = Len(UserAgent)
   
FindFirstSplit = CInt(InStr(1,UserAgent,";")) + 1
    FindSecondSplit
= CInt(InStrRev(UserAgent,";")) + 1
    FirstLength
= CInt(FindSecondSplit - FindFirstSplit) - 1
    SecondLength
= CInt(UserAgentLength - FindSecondSplit)
   
ExtractBrowser = Mid(UserAgent,FindFirstSplit,FirstLength)
   
ExtractOS = Mid(USerAgent,FindSecondSplit,SecondLength)

Response.Write "The borwser is: " & ExtractBrowser & "<br>"
Response.Write "The OS is: " & ExtractOS
?>

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I would have done it this way:

UserAgent = Request.ServerVariables("HTTP_USER_AGENT")

If InStr(1,UserAgent, "Windows") <> 0 Then
    'do something
ElseIf InStr(1,UserAgent, "anotherOS") <> 0 Then
    'do something else
Else
    'do some generic thing
End If

If InStr(1,UserAgent, "MSIE 5") <> 0 Then
    'NOTE this will catch "MSIE 5.0" and "MSIE 5.5"
    'do something
ElseIf InStr(1,UserAgent, "Netscape") <> 0 Then
    'I don't use NN so I'm guessing that it returns 'Netscape' something
    'do something else
Else
    'do something generic
End If
'

I don't have ASP support at home, so I'll have to play with it elsewhere. Anyway, at least the User Agent should work.

Mark Hensler
If there is no answer on Google, then there is no question.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Max,

Our code is totally different, you're searching the HTTP_USER_AGENT for a match whereas I am extracting the browser and OS information and storing them in variables.

If I just wanted to do detection then your code makes sense, but from my interpretation of hotcut's last post it sounded like he wanted to separate and store the values not just detect which browser or OS.

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

unless your going to spit out the values to the visitor, your going to have to evaluate the value of the vars everytime you want to use them.
So, intead of evaluating a custom var, I like to evaluate the environmental var.
that saves me the lines of code that it took you to put the values into custom vars.

Make sense?

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

Quote: Originally posted by Max Albert
unless your going to spit out the values to the visitor, your going to have to evaluate the value of the vars everytime you want to use them.
So, intead of evaluating a custom var, I like to evaluate the environmental var.
that saves me the lines of code that it took you to put the values into custom vars.

Make sense?

ehhh... no Sad

As I said before, I want to make a statistik counter.
I want to make the page save the different OS-, and browser-types into a database.
So what I need is just to put it all into variables, and then put them into the database.

I conclude that Peter's solution will be the most propper one for my need.

The problem is then... How do I make the script, so that it will deteckt weather the user is using netscape, microsoft, or other.

Example:

I am using netscape.
I have 3 variables.
1: dim netscape
2: dim microsoft
3: dim other

Then I want the value of the variables (in my example) to be:
netscape = 1
microsoft = 0
other = 0

etc...

So that I will store the data in 3 variables, like that... I think that you should use something like

if browser <> microsoft AND browser <> netscape then
netscape = 0
microsoft = 0
other = 1

But in realaty, that wont work... Can you please tell me how to do that?

Sincere
-Casper

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

this will have serveral steps.
Step 1:
Query your DB and get the current number for each browser.
Step 2:
Detect the browser in use, and increment the number.
Step 3:
Put the numbers back into the DB.

From where I'm standing, there is no need to store the browser or OS in a var. Just 'look' for them in the HTTP_USER_AGENT and increment. I made two codes. The first is mine. The second is what I think you'll need to use Peter's code.

I'll let you decide how you set up your DB, and put the value into vars. So I'll start my code with those vars.

<%
'STEP 1 will return vars like this:
'IE = count for Internet Explorer
'NN = count for Netscape
'Other = count for everything else (duh)

'STEP 2
UserAgent = Request.ServerVariables("HTTP_USER_AGENT")
If InStr(1,UserAgent, "MSIE") <> 0 Then
    'NOTE this will catch "MSIE 5.0" and "MSIE 5.5"
    IE = IE + 1
ElseIf InStr(1,UserAgent, "Netscape") <> 0 Then
    'I don't use NN so I'm guessing that it returns 'Netscape' something
    NN = NN + 1
Else
    Other = Other + 1
End If

'STEP 3 will put the vars back into the DB
SQLstmt = "UPDATE ...
%>
'
<%
'STEP 1 will return vars like this:
'IE = count for Internet Explorer
'NN = count for Netscape
'Other = count for everything else (duh)

'STEP 2
UserAgent = Request.ServerVariables("HTTP_USER_AGENT")

UserAgentLength = Len(UserAgent)
FindFirstSplit = CInt(InStr(1,UserAgent,";")) + 1
FindSecondSplit = CInt(InStrRev(UserAgent,";")) + 1
FirstLength = CInt(FindSecondSplit - FindFirstSplit) - 1
SecondLength = CInt(UserAgentLength - FindSecondSplit)
ExtractBrowser = Mid(UserAgent,FindFirstSplit,FirstLength)
ExtractOS = Mid(USerAgent,FindSecondSplit,SecondLength)

If InStr(1,ExtractBrowser, "MSIE") <> 0 Then
    'NOTE this will catch "MSIE 5.0" and "MSIE 5.5"
    IE = IE + 1
ElseIf InStr(1,ExtractBrowser, "Netscape") <> 0 Then
    'I don't use NN so I'm guessing that it returns 'Netscape' something
    NN = NN + 1
Else
    Other = Other + 1
End If

'STEP 3 will put the vars back into the DB
SQLstmt = "UPDATE ...
%>
'

Notice that whether the 'browser' is put into an array or not, you have to 'look' for the browser? You can't just say if ExtractBrowser = "MSIE" Then because you'd have to check it against every variation of IE (MSIE 5.0, MSIE 5.5, etc.).

If I'm wrong, let me know. There may well be an easier way of doing this.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 133 posts

Joined: Sep 2000

Hi,

I have been looking at the 2 scripts, and it seems like I can make it with that information...

I am not using netscape either, so if anyone is reading this, can you please tell me, what result it will give... Max thourght that it is :'Netscape' but I cant know, since I have no way of detecting it...
Can you help me out on this, someone?

Anyway, that ansvered 1 of my questions... I allso need to find the OS, I dont suppose that that will be hard, I think that you can just do it the same way, as the other...
I think that I will store the OS in 2 variables, one called PC, and one called MAC
What exactly shall I search for, when I want to find out weather it is a mac? Can I be that lucky, so that I can just split it up after the word "mac"??

Anyway, thanks for you help
-Casper

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.