Automatically switching index page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aegiss
Forum Newbie
Posts: 9
Joined: Sat Jun 24, 2006 11:48 pm

Automatically switching index page?

Post by Aegiss »

Hey guys. I was wondering if there's a way to automatically change my main page on a certain time in the week. See I have a site for a radio show that i do every sunday night from 9 to midnight and i want to switch to a page that has a big blinking LISTEN NOW link on the main page when it's 9 p.m. and then back to normal at midnight. Is there any way to do a little time-based switcharoo here with php? I'm familiar with cron jobs if that would help. Thanks!
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: Automatically switching index page?

Post by aerodromoi »

Aegiss wrote:Hey guys. I was wondering if there's a way to automatically change my main page on a certain time in the week. See I have a site for a radio show that i do every sunday night from 9 to midnight and i want to switch to a page that has a big blinking LISTEN NOW link on the main page when it's 9 p.m. and then back to normal at midnight. Is there any way to do a little time-based switcharoo here with php? I'm familiar with cron jobs if that would help. Thanks!

Code: Select all

<?php
if ((date("G") >= 21) && (date("w") == 0)){
  header("Location: http://www.inexistantdomain.net/");
  exit;
}
?>
This should redirect you to another page on sundays between 9pm and 11:59pm.
However, don't send any headers before this snippet is called!
Aegiss
Forum Newbie
Posts: 9
Joined: Sat Jun 24, 2006 11:48 pm

Post by Aegiss »

ok i'll try that. it's 9-12 central time though. Is there a way to set that in the code? just wondering if someone on the west coast would get something different
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

php is going to pull the time from your server, so it doens't matter where the user is
Aegiss
Forum Newbie
Posts: 9
Joined: Sat Jun 24, 2006 11:48 pm

Post by Aegiss »

hmm does the location of my server matter then? im not sure where its located
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Location doesn't matter at all. It only matters what time your server thinks it is :)
Aegiss
Forum Newbie
Posts: 9
Joined: Sat Jun 24, 2006 11:48 pm

Post by Aegiss »

hehe ok and how can i determine what it's thinking?
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Code: Select all

echo date('O');
Compare that timezome to your timezone and then +/- hours from the date you display.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Make sure you account for the server location. I had a server located in Florida though my target audience was in California. It took me a few days before I realized I had to adjust the date/time display for three hours back.
Aegiss
Forum Newbie
Posts: 9
Joined: Sat Jun 24, 2006 11:48 pm

Post by Aegiss »

ah good deal. turns out its eastern. good to know :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

BTW, do you need an entire redirect or can you just throw some time related content?
Aegiss
Forum Newbie
Posts: 9
Joined: Sat Jun 24, 2006 11:48 pm

Post by Aegiss »

no i think redirect would be best. It works fine like that.
Post Reply