Redirect base on the time of day at server location - datetime

I'm looking for a solution to redirect the user to a different page depending on the time of day at the server location.
I'm aware of some methods but to my knowledge they all get the time from the client.
Any suggestions?

Related

Is there a coding that can find server time of a particular site in R?

Need to find the exact server time of an particular site(that actually flows or refreshes every millisecond)
If there is a way can you walk me through?
Not sure what you want to do.But you can download a html file using
utils::download.file(URL, target_file_path)
Best you can hope for I think is to use some IP Geolocation API to guess the location of said webserver, heuristically determine his timezone and assume a bunch of things, such as:
the server is using his local timezone (instead of UTC);
the server's clock is properly synchronised using NTP;
the server is not located behind reverse proxies in some other location.
If these hold true you have your answer (server time of a given server)

Is it possible to redirect a URL at a certain datetime via IIS (web.config)?

I need a redirect that activates at a certain date at midnight. Is it possible to implement that via url rewrite? I mean as xml in web.config? How?
No because you cannot know if there will be any traffic that could be redirected at that precise time. What you need to do is write a separate process (it could be as simple as some VBScript or Javascript that gets triggered by a Task Scheduler job) which would make the request at the specified time.

Detect infinite HTTP redirect loop on server side

Is there a way to detect infinite HTTP 3xx redirect loops on the server? (Not necessarily the exact moment when the client gives an error, as the number of redirects required for that is client-dependent, but log an error after, say, 10 continuous redirects.)
The redirects come from the application code in a LAMP environment. I can change the code, but don't want to change the URL so adding some sort of counter to it is out of the question. I suppose I could use the session to count the number of redirects and erase that count on each non-redirect request, but that is brittle because the session is shared between several browser windows. Is there another way (such as using some HTTP header which the browser would mirror back)?
There is no 'standard' way.
You should probably approach it with sessions. Only count urls that redirect, but also keep a timer, because you'd only want to trigger if the redirects happen in a very short timespan.
Of course, fixing the cause is much better than patching the symptoms.

Measuring time between client starts request in browser until server gets it

Is there a way to measure this?
Certainly, for get requests, no available headers are being sent consistently from clients.
One idea I got is to get that from query string, but is that possible? Something like (pseudo-code follows)
http://server/default.aspx?t=(new Date().getTime())
Another one that would work is to have users hit a very small page that appends a query string as above, but wanted to avoid a redirection if possible.
(Overall goal is to gather per-request such statistics. The server processing time and server to client are more doable, under some assumptions.)
Thanks in advance.
I've done this through an AJAX request after the initial page load where you have control over the request from the very beginning. Pass the UNIX time in the query string and then when it reaches the server take the difference. I'm not familiar with iis7 so you'd have to make sure that timezone's are accounted for. This number could be very erratic since it's basically just calculating latency and DNS lookups which is different for every client.
Does the request start from an initial page that you have control over it ? in that case you can send the server time with the initial response, and then increment that time second-by-second with a javascript code while the user is on the page. this way you can have a server-synchronized time on the page and when a request goes to be sent from that page you can send that synced time with that request, then all you need is calculate difference on the server.

Retrieve Client Time with ASP.NET

Is it possible to request the time on a client computer with ASP.NET without using javascript?
i don't believe so. javascript executes on the client and therefore has access to the client attributes. asp.net code behind files are procesed on the server and therefore do not have access to client data.
Agree with jmatthews.
What I do is on login to the system, I have javascript to write the client time to a hidden field, then when the page posts I use that to compute an offset vs the server time. Anytime in the application I need the client time I can just apply the offset to the current server time. Saves having to "ask" for it at a random point, if that helps.
The only information about the client that the server can see without JavaScript is what comes over the wire in the HTTP headers. Unfortunately, that doesn't include the current time.
About the closest you can get without script is to measure approximate elapsed time, with coarse granularity. You could do that by setting a cookie with a short expiration time, and then looking to see if the cookie has expired, in which case it will no longer be sent to the server.
Another trick for elapsed time would be to set a short cache expiration time on an object on the page; the object will only be requested again once the cache entry expires.
You can also estimate the current local time at the client by using a GeoIP database to find the country and therefore the time zone.

Resources