[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 1997-06-07
4
Medium Priority
?
265 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 320 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
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 how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 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