General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 5th, 2003, 11:15 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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?

Reply With Quote
  #2  
Old January 11th, 2003, 11:09 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
Simply done using unix timestamps and a conditional ->

PHP Code:
 $_t = ( int ) date'G' );

if ( ( 
$_t >= 22 ) && ( $_t <= ) )
    {
    
header'location: page.php' );
    exit();    
} else
    {
    echo 
'It is before 10:00pm or after 12:00am';



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.




Reply With Quote
  #3  
Old January 11th, 2003, 01:11 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #4  
Old January 11th, 2003, 02:19 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
Quote:
Do I basically put that code anywhere in my html page?

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

Reply With Quote
  #5  
Old January 11th, 2003, 02:33 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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....

Reply With Quote
  #6  
Old January 11th, 2003, 03:36 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
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:
 $_t = ( int ) date'G' );

if ( ( 
$_t >= 10 ) && ( $_t <= 12 ) )
    {
    echo 
'<a href="link_to_page">Click here</a> to view broadcast.';
} else
    {
    echo 
'The broadcast is currently not running.';



Are your pages php pages. If not, you could probably use SSI's with include files to make it work...

Reply With Quote
  #7  
Old January 11th, 2003, 04:01 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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??

Reply With Quote
  #8  
Old January 11th, 2003, 04:24 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
Oh, forgot about the day...

PHP Code:
 $_t = ( int ) date'G' );
$_d = ( int ) date'w' );

if ( ( 
$_t >= 10 ) && ( $_t <= 12 ) && ( $_d == ) ) 
    {
    echo 
'<a href="link_to_page">Click here</a> to view broadcast.';
} else
    {
    echo 
'The broadcast is currently not running.';



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...

Reply With Quote
  #9  
Old January 11th, 2003, 05:32 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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))

Reply With Quote
  #10  
Old January 11th, 2003, 05:49 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
Well, yes. You would add another statement or clause ->

PHP Code:
 $_t = ( int ) date'G' );
$_d = ( int ) date'w' );

if ( ( 
$_t >= 10 ) && ( $_t <= 12 ) && ( $_d == ) ) 
    {
    echo 
'<a href="link_to_page">Click here</a> to view broadcast.';
}
elseif ( ( 
$_t >= 10 ) && ( $_t <= 12 ) && ( $_d == ) ) 
    {
    echo 
'<a href="link_to_page">Click here</a> to view broadcast.';
}
else
    {
    echo 
'The broadcast is currently not running.';



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:
 $_s = ( bool ) false;
$_t = ( int ) date'G' );
$_d = ( int ) date'w' );

if ( ( 
$_t >= 10 ) && ( $_t <= 12 ) && ( $_d == ) ) $_s = ( bool ) true;
if ( ( 
$_t >= 10 ) && ( $_t <= 12 ) && ( $_d == ) ) $_s = ( bool ) true;

if ( 
$_s )
    {
    echo 
'<a href="link_to_page">Click here</a> to view broadcast.';
}
else
    {
    echo 
'The broadcast is currently not running.';


Of course if the link isn't the same, you would have to use the conditional as originally posted...

Reply With Quote
  #11  
Old January 11th, 2003, 06:02 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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?

Reply With Quote
  #12  
Old January 11th, 2003, 06:27 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
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...

Reply With Quote
  #13  
Old January 11th, 2003, 06:42 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Check Server Time


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |