Jump to content
Science Forums

Recommended Posts

Posted

Anyone care to help my problem with PHP?

I got the script for to get the number of users currently online on a website. the problem is that it only counts the users online on that page, not the whole website. therefore i have to put it on each page (i have over 4000 pages) which is unpractical. so can anyone modify or suggest a better code that would work from this one:

http://www.devarticles.com/c/a/MySQL/Display-Users-Online-Based-On-Page-Viewing/1/

i appreciate your help

 

PS: Is it ok for me to treat this category for computer problems?

  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

Posted
PS: Is it ok for me to treat this category for computer problems?

 

I'm still learning PHP myself but I think it is perfectly fine to post help requests here. Alexander is a PHP programmer. ;)

Posted
Is it ok for me to treat this category for computer problems?[/Quote]

Remember, this section was called "Computer Programming" in the past, plus remember i posted in "xrand reloaded" thread a whole bunch of code? So yes this is very appropriate and welcome here!

 

You have to excuse me, i tend to be away for weekends, job, school work, you know how it goes...

Posted

Thank you very much but it wasn't of much help.... I actually have tried almost all the php free scripts available on the internet prior to giving up and hoping alex would solve it. theones on the net ALL work the same. the method used is the timeout method.

the problem is here:

$timeout = time() - 300 //this is in seconds

so the query goes:

"delete from database where timevisit<timeout"

$result = "select distinct IP from database"

$user = number_of_rows($result)

to display it, it goes:

there are $user users online.

 

So basically, you don't know when the visitor exits the website. the code simply deletes the IPs of visitors who registered their IP more than five minutes (300 seconds) ago. so if the visiotr is still on the site more than five minutes they will not be counted as one that is currently online. or, if the visitor left after a minute, the visitor will still be counted as online. that would make it totally inaccurate.

 

ONe more thing, do you know how the '$REMOTE_ADDR' variable obtains the IP address of visitors.because I compared the list of IPs using that variable and the list of IPs obtained from the statistics software and they were different. the statistics software records more IPs. it seems the '$REMOTE_ADDR' variable doesn't pick up certain IPs. how is this? or is the webalizer software wrong.FIY, webalizer as well as most others i know obtain the info from the log file. is it the same with '$REMOTE_ADDR'? if not, where do i find the log file?

thanks for reading... ;)

Posted

Session timeout is always a problem. 5 minutes is too short, though.

 

At Hypography this is set to 15 minutes, I think. So if you read an article for 15 minutes, then post, you might be counted as two visitors in the stats. But the "Users online right now" will be correct until the 16th minute. However, when you reload you will again be counted so this isn't a real problem.

Posted
$REMOTE_ADDR is a PHP server variable which provides the referral address. This is not received from the log but from the browser, and is then stored in the log.
oh.. i see. how do you know that? is it accurate? have you compared it with the statistics software?

maybe obtaining it from the log file is better? how does the browser provide the IP?

i'm quite sure there's something wrong with the $REMOTE_ADDR thingy.

Posted

I would not do anything towards the log files as they are constantly being updated by the server.

 

I don't know what you mean with "accurate" - it simply contains the full URL from which the user has arrived to your site (so if the previous page was on your site, it will contain the full url to some page on your site. It is as accurate as it gets - that means, nothing is quite reliable and accurate when it comes to web statistics. I think you will find that your numbers will never add upp correctly no matter how you try. So go for an approximation and you should be fine.

Posted
I don't know what you mean with "accurate" - it simply contains the full URL from which the user has arrived to your site (so if the previous page was on your site, it will contain the full url to some page on your site
no, the variable is for retrieving people's IP address, not previous url.

i'm just wondering that perhaps certain people's IPs aren't available through that variable. coz it doesn't show all the ip's that i find from the webalizer program.

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