So I don't know a thing about PHP and I'm trying to get a page to redirect to another page based on what day it is. I found the code below that sounded like it was going to be perfect for what I needed, except it doesn't appear to work, it always uses the last line of code for the redirect regardless of day. Could you take a look at this and help me figure out what's wrong? I spent last night trying to figure this out myself, but just no luck (like I said, I don't know anything about PHP).
This is the code I was using:
<?php
date_default_timezone_set('America/Los_Angeles');
$b = time () ;
$day = date("D",$b) ;
//Here we redirect the user to a different programming site based on what day of the week it is.
switch($day){
case "Sun": header( 'Location: http://php.about.com' ) ;
case "Mon": header( 'Location: http://webdesign.about.com' ) ;
case "Tue": header( 'Location: http://javascript.about.com' ) ;
case "Wed": header( 'Location: http://perl.about.com' ) ;
case "Thu": header( 'Location: http://python.about.com' ) ;
case "Fri": header( 'Location: http://ruby.about.com' ) ;
case "Sat": header( 'Location: http://cplus.about.com' ) ;
}
?>
Question
dbeck666
Hey,
So I don't know a thing about PHP and I'm trying to get a page to redirect to another page based on what day it is. I found the code below that sounded like it was going to be perfect for what I needed, except it doesn't appear to work, it always uses the last line of code for the redirect regardless of day. Could you take a look at this and help me figure out what's wrong? I spent last night trying to figure this out myself, but just no luck (like I said, I don't know anything about PHP).
This is the code I was using:
<?php date_default_timezone_set('America/Los_Angeles'); $b = time () ; $day = date("D",$b) ; //Here we redirect the user to a different programming site based on what day of the week it is. switch($day){ case "Sun": header( 'Location: http://php.about.com' ) ; case "Mon": header( 'Location: http://webdesign.about.com' ) ; case "Tue": header( 'Location: http://javascript.about.com' ) ; case "Wed": header( 'Location: http://perl.about.com' ) ; case "Thu": header( 'Location: http://python.about.com' ) ; case "Fri": header( 'Location: http://ruby.about.com' ) ; case "Sat": header( 'Location: http://cplus.about.com' ) ; } ?>Thank you all so much!
Dean
Link to comment
Share on other sites
7 answers to this question
Recommended Posts