Jump to content
Science Forums

'Users Online' PHP script


TINNY

Recommended Posts

  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

no, no its just receiving them the wrong way... you see, $_SERVER vars are automagically global, so no matter what they are available, but if whoever hosts this stuff has global vars on, you can also access them via $REMOTE_ADDR for example for remote adress or $REMOTE_PORT for port, the problem is when people write the source they at times forget where the data comes from and how to get it in a way so it workd for everyone. You technically are supposed to get these vars via $_SERVER['REMOTE_ADDR'], so there could be a problem with your server Tinny, it could have gobal variables turned off.

 

Also, it returns an ip passed by your browser, if someone goes through a proxy to get to your site, then you get the proxy adress, you cant get the true ip with any web-based language... We can setup some king of an experimet to help you see this...

Link to comment
Share on other sites

You technically are supposed to get these vars via $_SERVER['REMOTE_ADDR'], so there could be a problem with your server Tinny, it could have gobal variables turned off.
do you mean that i should change $REMOTE_ADDR to $_SERVER['REMOTE_ADDR']?
Also, it returns an ip passed by your browser, if someone goes through a proxy to get to your site, then you get the proxy adress, you cant get the true ip with any web-based language... We can setup some king of an experimet to help you see this...
how significant does that affect you? can you explain a bit about the proxy server. are ISPs proxies or not?

why do the data from the statistics software differ fromthe data i get in mysql through php?

how do i access the log file?

i really appreciate the help here. i dont know these things...

Link to comment
Share on other sites

do you mean that i should change $REMOTE_ADDR to $_SERVER['REMOTE_ADDR']?[/Quote]

I suggest that you try that first...

how significant does that affect you? can you explain a bit about the proxy server. are ISPs proxies or not?[/Quote]

"A proxy server is a computer network service which allows clients to make indirect network connections to other network services. A client connects to the proxy server, then requests a connection, file, or other resource available on a different server. The proxy provides the resource, possibly by connecting to the specified server, or by serving it from a cache. In some cases, the proxy may alter the client's request or the server's response for various purposes." from wiki

Yes your ISP is a proxy that assigns you an ip whenever you get on the network. This IP is the one displayed by remote_addr, but since you dont connect to a different ISP every second it remains static until you disconnect and reconnect.

why do the data from the statistics software differ fromthe data i get in mysql through php?[/Quote]

they must look at different things, tell me more about this and i might be able to help, what are you doing, how are you checking, scripts, maybe even post some code so i can understand what exactly is going wrong...

how do i access the log file?[/Quote] through PHP? if yes than you need to write little advanced file-managing code. If no, its somewhere on the server you use...
Link to comment
Share on other sites

Hey, actually i just noticed something similar discussed on another forum so here:

The trouble is there's no "disconnection" to catch. As soon as your browser finishes loading the page, it is disconnected. Right now, as I'm typing this into the phpBB box, I'm not connected to the server, and as you're reading it, you're not connected to the server, either (unless it's still loading, I suppose).

 

That's where sessions come in. When you see a forum that says "15 users online", all it really means is that 15 users have visited (i.e. loaded a page) inthe last X minutes. None of them are actually "connected", unless they're in the middle of loading a page.

 

That's essentially how sessions work, too -- if the session has been accessed in the last X minutes, it remains active; if it hasn't been, it's removed.

 

There is no way you can know whether the user has hit the stop button or closed the browser, and if you think about it...[/Quote]

I think this will clear a few things for you on how this type of software works and why its not accurate...

Link to comment
Share on other sites

so all websites with the 'users online' script accepts this problem and they just get along with it?

 

when i checked the iP's I'm getting with the PHP code, about 90% were from malaysia. but when i used the webalizer statistics software, malaysian IP's account for only 0.5%. that's a shocking difference. but the PHP one does not specify exactly the country that the iP's indicates. I just assume that ones that are 219.xx.xx.xxx are from malaysia. it is true though right? i also notice that the statistics software shows 35% of the IP's were unidentified. and I expected many INdonesian visitors, but there were none. how do you explain that?

but thanks alot for the help

Link to comment
Share on other sites

so all websites with the 'users online' script accepts this problem and they just get along with it?

 

There are of course different solutions, but like both I and Alexander have said you never know when a session ends so there's really not much you can do. When you ask for a page here at Hypography, you get it served in bits and pieces via many connections at once (that is how the IP network functions).

 

So what we do is estimate an acceptable time limit for which we say "okay, if no activity has been recorded in X minutes, the user is no longer online".

 

So if you call it "Users online in the past 15 minutes" or so you would basically be correct....but there are caveats (see below).

 

when i checked the iP's I'm getting with the PHP code, about 90% were from malaysia. but when i used the webalizer statistics software, malaysian IP's account for only 0.5%. that's a shocking difference. but the PHP one does not specify exactly the country that the iP's indicates. I just assume that ones that are 219.xx.xx.xxx are from malaysia. it is true though right? i also notice that the statistics software shows 35% of the IP's were unidentified. and I expected many INdonesian visitors, but there were none. how do you explain that?

 

There are some major problems with tracking users by IP. First of all, AOL users have multiple IPs. When they browse the web, each request seems to come from a different IP (because AOL uses proxies). So each and every request for images, files etc might appear to come from different users even though they are in fact from one user only.

 

Second, if your site is spidered a lot by search engines, this will inflate your stats. I filtered out all spider traffic (as well as I could) in May and our overall traffic stats dropped 30% (!) instantly.

 

So the script you see on this site uses cookies to track users, combined with a database table for each cookie. Each user only gets one cookie and it is the availability of this cookie that tells the script whether the user is online or not. If the cookie has not been read for 15 minutes, then the user is considered offline.

Link to comment
Share on other sites

Second, if your site is spidered a lot by search engines, this will inflate your stats. I filtered out all spider traffic (as well as I could) in May and our overall traffic stats dropped 30% (!) instantly.
but then your site won't do well in search engines right?
So the script you see on this site uses cookies to track users, combined with a database table for each cookie. Each user only gets one cookie and it is the availability of this cookie that tells the script whether the user is online or not. If the cookie has not been read for 15 minutes, then the user is considered offline.
good idea. so only one cookie to each user for that page only, or use the same cookie for all pages by the same ip? sure, i'll try this idea.

how do you overcome the proxy problem?

I just assume that ones that are 219.xx.xx.xxx are from malaysia. it is true though right? i also notice that the statistics software shows 35% of the IP's were unidentified. and I expected many INdonesian visitors, but there were none. how do you explain that?
and how about this one which i posted earlier?
Link to comment
Share on other sites

but then your site won't do well in search engines right?

 

No, I don't restrict their access. I filter out their IP addresses from the logs before making the reports.

 

good idea. so only one cookie to each user for that page only, or use the same cookie for all pages by the same ip? sure, i'll try this idea.

how do you overcome the proxy problem?

 

The cookie sits on the client (ie, the user's browser) and does not care what IP it's transmitted over. So the cookie thing is a solution in itself. You just need a script which checks if the cookie exists, if no, set it. If yes, how long since it was accessed. If more than 15 minutes, reset it and count as new user.

 

BUT then there is the problem of users who will not accept cookies. Some people have cookies turned off and this will not be counted. I have no solution for that.

 

and how about this one which i posted earlier? (Malaysian visitors)

 

When I first started Hypography I was surprised that so much traffic came from the US. It turned out that many of the companies selling web connections in Norway are either affiliated with or owned by US companies, so they use IP address ranges which actually traces back to the US.

 

I have no solution to it.

 

I think currently that about 10% of the traffic to Hypography.com is "unknown", which means that the IP did not resolve to anything.

Link to comment
Share on other sites

No, I don't restrict their access. I filter out their IP addresses from the logs before making the reports
how'd you get their IP's?
I think currently that about 10% of the traffic to Hypography.com is "unknown", which means that the IP did not resolve to anything.
do you use webalizer? how does it determine the countryof the ip. the first group of numbers? is it definite?
It turned out that many of the companies selling web connections in Norway are either affiliated with or owned by US companies, so they use IP address ranges which actually traces back to the US.
what's web connections? ISP's?
Link to comment
Share on other sites

Tinny, you cant do anything about proxies, you cant track a user through them, not without very spcial access to all of them...

 

AOL owns 205.188.x.x block, they have numerous proxies and servers set up so people will have a hard time blocking AIM, well the rest of users use them too because of the system that they setup, its quite stupid actually, but I'm not them. Shoot, i gotta run to class, but i'll finish my thought eventually.

Link to comment
Share on other sites

how'd you get their IP's?

do you use webalizer? how does it determine the countryof the ip. the first group of numbers? is it definite?

 

No, at Hypography.com we use SmarterStats from SmarterTools. It comes with the hosting package.

 

I think they just do a basic reverse DNS loopup, i.e. it queries a DNS server and asks "give me some info on this IP". This setting is usually called "Perform reverse DNS lookup" or something (Webalizer supports this - google webalizer reverse dns for info).

 

what's web connections? ISP's?

 

Yes, sorry, I meant the ISP networks.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...