Detect RELOAD in cgi and how to figure out the date?

I want to know if someone is reloading my page(ie, click the
RELOAD button), can I  use some variables in cgi to do this?

How to get the date since there is no such environment variable available? please tell me in details. (say currentTime = date(...) or something like that)

And finally, I want to figure out who are currently on
my page, that is, to find out all the users who are currently on my page.(use REMOTE_ADDR can get only one
of them)

Thanks.
carrotAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

n3mtrCommented:
I have an answer for the second question(date).  You need to use the time function(gives you seconds since 1970) then feed that into the localtime function.  It returns a list with the date:
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)= localtime(time);
$mday is the day of the month
$mon is the month
$year is the year
$wday is the day of the week

0
jpk041897Commented:
Regarding the first question:

You could set up an invisible applet on your page. Whenever a page is loaded (or reloaded) Java's Applet.start() method is called. You could set up a counter that determines how many times the page has been loade. If > 1, and the time frame is less than say 5 or 10 seconds, the user is refreshing the page.

Re.: question 2, an applet can detect the IP of the user that loaded it, it could transmit this info, via a socket, to a remote server.

Re.: question 3, an applet can also obtain time information and save it on a file on the host.

Of course, you posted this question on the CGI topic section so I don't know if an applet solution is acceptable to you, thus I post as a comment and don't give additional details.

Your CGI code could read a file generated by an applet though, to obtain the info you require so, if no one can produce a better answer and/or a combination applet/CGI solution is acceptable I'd be glad to post an answer with additional details.
0
julio011597Commented:
Ok, my turn:)

1. hitting 'Reload' just makes your browser contact the web server and get the current page again; the only difference between submitting a url and hitting 'Reload' should be that, in the latter case, the browser wouldn't care of document's date and would override its own caching.

So, how to detect a 'Reload'? The only trusted method that comes to mind is to look at the web server access log file:
each request is logged, and you may check for the status code of the answer; each page send by the web server generates a 200 code (the OK code), but a page already send to a browser and unchanged in the meantime, generates a 304 code ('Not Modified')- anyway, check your server documentation for status codes.

This means that:
when a user asks for a page, the web server answers with a 200 code (the page is sent);
if the user goes to that page again (with a 'Go' menu command or entering the url in the 'Location' area), and the page is in the browser's cache, no request is submitted to the web server, and the browser reads its cache;
if the user hits 'Reload', the browser contacts the web server, which, at its turn, answers with a 304 code ('Not Modified').

This said, please note that, if the url actually points to a CGI, the server answer is _always_ 200 (and the CGI is run), so, in the CGI case, there seems to be NO way to check for a reload.

2. n3mtr's answer works fine if your language is Perl; here is the corrensponding C code:

--//--
#include <time.h>

char time_string[32];
time_t timer;

/* timer = secs since the Epoch (1 Jan 1970) */
timer = time(NULL);
/* time_string = something like: "Tue Nov  9 15:37:29 1993" */
strcpy(time_string, ctime(&timer));
--//--

Have a look at time(3) and ctime(3) for reference.

3. There is NO way to detect who are currently on your page; this is because of the concept underlying the HTTP protocol itself: open a connection, give the file, _close_ the connection; i.e., once you've given the page, you lose any contact with the client.
The only workaround would be a Server Push, or some Javascript, to keep the connection open; but note that this may dramatically increase your web server load.
Think that, usually, a web server keeps a connection open for a few seconds (maybe less); with server push (or such), each client needs his/her own connection for as long as (s)he stay on your page, and your web server may end up serving lots of sockets at the same time.

Hope this makes things a bit clearer,

-julio

P.S. IMHO, this answer is worth more than 80 points.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
carrotAuthor Commented:
This answer helps a lot, thanks.
but I can't give more points since I have nearly none
left. Think I may want to ask one or more questions. ^.^

Thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.