Solved

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

Posted on 1997-06-07
4
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Expert Comment

by:n3mtr
ID: 1828190
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
ID: 1828191
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
ID: 1828192
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
ID: 1828193
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

728 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