Solved

Day of Week Redirect

Posted on 2003-10-30
19
312 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:ddh86
  • 6
  • 6
  • 5
  • +1
19 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9654997
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
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9654998
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
 

Author Comment

by:ddh86
ID: 9655201
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 13

Expert Comment

by:lozloz
ID: 9655242
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9655453
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9655462
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
 

Author Comment

by:ddh86
ID: 9657223
ok thanks guys, ya gotta give me a chance to try them now.

javascript is client-side, right?
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9657587
Yes JS is Clientside
0
 

Author Comment

by:ddh86
ID: 9659534
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
 
LVL 13

Expert Comment

by:lozloz
ID: 9659626
rename index.htm to something else and have that code in your new index.htm?
0
 

Author Comment

by:ddh86
ID: 9659882
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
 
LVL 13

Expert Comment

by:lozloz
ID: 9659933
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
 

Author Comment

by:ddh86
ID: 9660002
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
 
LVL 13

Expert Comment

by:lozloz
ID: 9660090
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
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9660169
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
 
LVL 16

Accepted Solution

by:
jaysolomon earned 250 total points
ID: 9660211
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9660216
If you have asp it would be better
0
 

Author Comment

by:ddh86
ID: 9660352
jaysolomon - it looks like you're gettin the points! it works like a charm now.  Thanks a ton, all of you!
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9660395
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Owl Carousel 6 241
Getting Started on web Development for an experienced C++ developer 7 127
Magento Indexing 1 103
removing hyperlinks from end-notes in a PDF to HTML conversion 8 109
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question