|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Check Server Time
Hello,
I was wondering if I could get some help with a question. I'm trying to make a little functionality in a website i'm making on a volunteer basis. Basically what I want to do is have a link on the website....when the user clicks on the link.....the site contacts the server and checks what TIME it is (hour and minute) and based on the returned time (from the server)...perform a functionality... example...if it's 10:00 PM - 12:00 on the server then go to THIS URL....if it's any other then 10:00PM....to.....12:00 PM then display a page that says "SORRY" Error...whatever.... Any help? - i'm running on a UNIX box...so php...ssi...whatever works...? any idea how I would go about doing this? |
|
#2
|
|||
|
|||
|
Simply done using unix timestamps and a conditional ->
PHP Code:
date( 'G' ) returns the time() (hour only) in 24 hour format. So, we check to see if the unix server time is equal to or greater than 22 (10:00pm) and make sure if it is that it is also less than or equal to 0 (12:00am). If both are true, it executes, if either is false, it fails...
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#3
|
|||
|
|||
|
THANK YOU!
Do I basically put that code anywhere in my html page? or what - how do I use that peice of code? ALSO...this script executes during those two hours of the day accordingly...however, what if I wanted to restrict DAYS...monday, tuesday, wednesday...etc..aswell? How would I introduce a new variable for the days and use that? your help would be absoutely great! Last edited by kh44na : January 11th, 2003 at 01:24 PM. |
|
#4
|
|||
|
|||
|
Quote:
No.. Give me a little more info and I will build you something.The info I need is exactly what you are trying to do; ie: are you redirecting to another page depending on the server time; are you displaying a message depending on the server time; or what... Give me whatever you can on this.. ~ Thank You |
|
#5
|
|||
|
|||
|
Basically I have a LINK on my website (it's a volunteer website i'm working on for my community)
I want to link to another website which streams an audio program EVERY SUNDAY between 10-12, so people can click on the link and go there to listen to the audio stream LIVE.... The website i'm linking to belongs to the audio channel that hosts the radio show.... HOWEVER, I don't want to publicize their website when MY program isn't being broadcasted....(that's the whole reason for this time code restriction isssue i'm trying to figure out) I have a link on the left menu of my website that says LISTEN LIVE...now when people click on that link.....IF IT IS SUNDAY between 10-12 PM then I want the link to redirect the users to the broadcasting companies website where they can listen live.....and if it is ANY OTHER DAY....then I want to display an error that says, sorry there are no programs at this time...or whatever....(ON MY ACTUAL HTML PAGE inside my html layout...NOT ON A BLANK WHITE PAGE) [if that makes any sense?] your help is EXTREMELY appreciated... P.S....later on, I MAY need to add an extra day and timings....(ie...if it's FRIDAY between 6:00 to 7....OR SUNDAY 10:00-12:00.......just to keep that in mind.... I hope that helps....and once again thanks in advance for all your help.... |
|
#6
|
|||
|
|||
|
Ok, as long as your site or page is set up to use PHP, you can simply put this code block where you want the link or message to appear ->
PHP Code:
Are your pages php pages. If not, you could probably use SSI's with include files to make it work... |
|
#7
|
|||
|
|||
|
Alright - thanks
what about the other question....can I also use the DAY as well? so that if it's not SUNDAY....then it displays an error...and if it IS SUNDAY between 10-12 then it works? type thing?? |
|
#8
|
|||
|
|||
|
Oh, forgot about the day...
PHP Code:
Ok, the above adds the day or sunday to the code. The 0 represents sunday, so now the code is plugged to say if it is between 10:00am and 12:00pm on Sunday, then print the link; if not, present the user with the 'not running' message... |
|
#9
|
|||
|
|||
|
if ( ( $_t >= 10 ) && ( $_t <= 12 ) && ( $_d == 0 ) )
in that line...if I wanted to say if it's between 10-12 on sunday and monday....would I do it like this?: if (($_t >=10) && ($_t <=10) && ($_d == 0) && ($_d == 1)) |
|
#10
|
|||
|
|||
|
Well, yes. You would add another statement or clause ->
PHP Code:
EDIT::: To make the code a little more understandable, or easier to add more times - as long as the link is the same, this will work also -> PHP Code:
Of course if the link isn't the same, you would have to use the conditional as originally posted... |
|
#11
|
|||
|
|||
|
perfect
![]() learned more php today then ever before...if you dont mind I have ONE more question.... in the code that you gave me...IF THE CONDITION IS MET....THEN the link is displayed...... what if I want the link to be clicked FIRST...and THEN have the code executed? |
|
#12
|
|||
|
|||
|
Well, you could have a link on your page pointing to the script. So, when the link on the page is clicked, a pop-up window shows with the output of the code, showing click here to listen or program is currently not airing; or something like that...
|
|
#13
|
|||
|
|||
|
that was what I was thinking as well.
And I think it will be much easier to do as well.... anyways....I thank you once again for ALL YOUR HELP ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Check Server Time |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|