Solved

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

Posted on 1997-06-07
4
246 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:carrot
4 Comments
 
LVL 2

Expert Comment

by:n3mtr
Comment Utility
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
 
LVL 6

Expert Comment

by:jpk041897
Comment Utility
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
 
LVL 5

Accepted Solution

by:
julio011597 earned 80 total points
Comment Utility
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
 

Author Comment

by:carrot
Comment Utility
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now