Day of Week Redirect

Ok, heres my problem.  I need some type of script, be it javascript or vbscript or something that will let me load a different web page depending on the day of the week.  For example, i need to load index.htm on every day of the week except sundays.  on sundays, i want to load sunspecial.htm. Is there any way I can do this? I've been searching the web like a maniac trying to find answers but couldn't find anything that worked properly.  It's not a real complicated web site, just a few htm pages.
ddh86Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lozlozCommented:
if you have php installed..

change index.htm to index.php and add this code at the very top of the page:

<?
$date = date("w");
if($date == 0) {
  header("Location: sunspecial.htm");
  exit;
}
?>
0
kingsfan76Commented:
should be able to accomplish this with VBscript

<%
if WeekDay(Date) = 1    'today is Sunday
   response.redirect("sunspecial.htm")
else   'today is not sunday
   response.redirect("index.htm")
end if
%>

Weekday() function return the day of the week (1=sunday, 2=monday, etc.)

hope this helps   :-)
0
ddh86Author Commented:
Ok here's the status: neither of your solutions worked. I tried each one separately, and neither seem to react when i change my system clock to sunday. both give the same response on any day of the week.

one more question, kingsfan76: is sunday = 1 or 0? I tried it both ways.

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

lozlozCommented:
changing your system clock won't work, they both use the server's clock. are you sure you have asp or php available on your sever? and sunday is 1 in asp and 0 in php afaik

loz
0
jaysolomonCommented:
Javascript Solution

Sunday = 0

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin
function redirect(){
      var d = new Date();
      var today = d.getDay();
      if(today == 0){      location.href = "http://yahoo.com"; }
      else if(today == 1){ location.href = "http://microsoft.com"; }
      else if(today == 2){ location.href = "http://netscape.com"; }
      else if(today == 3){ location.href = "http://w3schools.com"; }
      else if(today == 4){ location.href = "http://oldlook.experts-exchange.com"; }
      else if(today == 5){ location.href = "http://experts-exchange.com"; }
      else if(today == 6){ location.href = "http://google.com"; }      
}
//End-->
</script>
</head>
<body onload="redirect();">

</body>
</html>
0
jaysolomonCommented:
or this

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin
var weekdays = new Array(7);
      weekdays[0] = "sunday";
      weekdays[1] = "monday";
      weekdays[2] = "tuesday";
      weekdays[3] = "wednesday";
      weekdays[4] = "thursday";
      weekdays[5] = "friday";
      weekdays[6] = "saturday";
function redirect(){
      var d = new Date();
      var today = d.getDay();
      if(today == 0){      location.href = "http://yoursite.com/"+ weekdays[0]; }
      else if(today == 1){ location.href = "http://yoursite.com/"+ weekdays[1]; }
      else if(today == 2){ location.href = "http://yoursite.com/"+ weekdays[2]; }
      else if(today == 3){ location.href = "http://yoursite.com/"+ weekdays[3]; }
      else if(today == 4){ location.href = "http://yoursite.com/"+ weekdays[4]; }
      else if(today == 5){ location.href = "http://yoursite.com/"+ weekdays[5]"; }
      else if(today == 6){ location.href = "http://yoursite.com/"+ weekdays[6]; }      
}
//End-->
</script>
</head>
<body onload="redirect();">

</body>
</html>
0
ddh86Author Commented:
ok thanks guys, ya gotta give me a chance to try them now.

javascript is client-side, right?
0
jaysolomonCommented:
Yes JS is Clientside
0
ddh86Author Commented:
hi jaysolomon: I used your first solution, and it works, the only problem is this: it first loads the entire index.htm page, and afterward redirects to sun.htm.  This works for me because i have DSL, but on dialup it'd be torture.  Can we fix that?

Thanx
0
lozlozCommented:
rename index.htm to something else and have that code in your new index.htm?
0
ddh86Author Commented:
Actually I'd prefer not to do that, I really want to keep the number of pages at a minimum.

Is there a way to execute that javascript before the entire page loads?
0
lozlozCommented:
not that i know of, im not the best at javascript though. both the asp and php scripts will process before the page loads though
0
ddh86Author Commented:
The problem with the asp and php is that i don't know how to test it to see if it works. . .

wait a minute. if i ran the html off my desktop, would it treat my computer as the server and run the script? that way i can set my clock to sunday and test it.
0
lozlozCommented:
no, you need php installed on a web server such as IIS or apache

but it will definitely work if you tell me the result of doing this:

<?
$date = mktime(0,0,0,11,2,2003);
$thedate = date("l - w", $date);
print $thedate;
?>

that simulates the day as 2nd of november and will return the day and index, so you'll know it works
0
kingsfan76Commented:
to test if it works, jsut do this:

<%
testDate = CDate("10/26/2003")     'i believe that was a Sunday
if WeekDay(testDate) = 1  then   'today is Sunday
  response.redirect("sunspecial.htm")
else   'today is not sunday
  response.redirect("index.htm")
end if
%>
0
jaysolomonCommented:
You can try to take the onload out of the body and take the function name out

<script type="text/javascript">
<!--Begin
     var d = new Date();
     var today = d.getDay();
     if(today == 0){     location.href = "http://yahoo.com"; }
     else if(today == 1){ location.href = "http://microsoft.com"; }
     else if(today == 2){ location.href = "http://netscape.com"; }
     else if(today == 3){ location.href = "http://w3schools.com"; }
     else if(today == 4){ location.href = "http://oldlook.experts-exchange.com"; }
     else if(today == 5){ location.href = "http://experts-exchange.com"; }
     else if(today == 6){ location.href = "http://google.com"; }    
//End-->
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaysolomonCommented:
If you have asp it would be better
0
ddh86Author Commented:
jaysolomon - it looks like you're gettin the points! it works like a charm now.  Thanks a ton, all of you!
0
jaysolomonCommented:
Glad we could help and thanks for the A

BTW
Here is you an asp solution
<%
      If weekday(date) = 1 Then      'Sunday
      response.redirect("http://yoursite.com/sunday.asp")
End If
%>
<%
If weekday(date) = 2 Then      'Monday
response.redirect("http://yoursite.com/monday.asp")
End If
%>
<%
      If weekday(date) = 3 Then      'Tuesday
      response.redirect("http://yoursite.com/tuesday.asp")
End If
%>
<%
      If weekday(date) = 4 Then      'Wednesday
      response.redirect("http://yoursite.com/wednesday.asp")
End If
%>
<%
      If weekday(date) = 5 Then      'Thursday
      response.redirect("http://yoursite.com/thursday.asp")
End If
%>
<%
      If weekday(date) = 6 Then      'Friday
      response.redirect("http://yoursite.com/friday.asp")
End If
%>
<%
      If weekday(date) = 7 Then      'Saturday
      response.redirect("http://yoursite.com/saturday.asp")
End If
%>
 

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

</body>
</html>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.