• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Is it possible to redirect a webpage during certain hours?

I want to disable a page between 9 am to 8:30 pm by redirecting to another page.
0
RaMb0z0
Asked:
RaMb0z0
  • 10
  • 8
1 Solution
 
RaMb0z0Author Commented:
Sorry i worded that wrong. I meant to say redirect the page between 8:30 pm and 9:00 am
0
 
radnorCommented:
Do you have PHP avail?  Or would you like a JS example?
0
 
radnorCommented:
PHP can be done with:

<?php

$server_to_local_time_offset = '0300';

$tod = (date('Hi')+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 900)) {
      header('evening page.htm');      // edit this for your evening page
} else {
      header('day page.htm');            // edit this for your day page
}
?>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RaMb0z0Author Commented:
I am using php but java would be fine too.
0
 
radnorCommented:
Well, the PHP example above would work.  Just figure out the difference in your local time from your server.  In my case, I had to add 3 hours.

I originally had echo('day') IN PLACE of the header('day page.htm').  That way I could test it.  You can do the same if you wish.

Also, I think I would ZERO my offset and add a echo($tod) to see what you have to add for your offest to amke it local time.

<?php

$server_to_local_time_offset = '0000';

$tod = (date('Hi')+$server_to_local_time_offset);
echo($tod);

?>
0
 
RaMb0z0Author Commented:
Guess I must be doing something wrong...can't see to get that to work.  This is where I thought I should place it, but its not working. This page contains a form...so what im trying to do is either prevent the user from filling it out or just redirecting them.
<?php else:
require_once("dbconnect.inc");
?>

<?php

$server_to_local_time_offset = '0300';

$tod = (date('Hi')+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 1030)) {
     header('index.html');     // edit this for your evening page
} else {
     header('register.php');          // edit this for your day page
}
?>

<?php

if (isset($_POST['phone'])) {
     $first = $_POST['first'];
     $last = $_POST['last'];
       $dob = $_POST['dob'];
       $phone = $_POST['phone'];
       $ins = $_POST['ins'];
     $addy = $_POST['addy'];
     $city = $_POST['city'];
     $state = $_POST['state'];
     $zip = $_POST['zip'];
               
$sql = "INSERT INTO reg_list SET
                    last='$last',
                    first='$first',
                    dob='$dob',
                    phone='$phone',
                              ins='$ins',
                    addy='$addy',
                    city='$city',
                    state='$state',
                    zip='$zip'";
                   
        
if (@mysql_query($sql)) {
  echo '<p><b>Success!</b></p>';
  } else {
    echo '<p>Error adding you to the waiting list: ' .
        mysql_error() . '</p>';
  }
}

                     
$result = @mysql_query("SELECT
                                    first,
                                    last,
                                    dob,
                                    phone,
                                    ins,
                                    addy,
                                    city,
                                    state,
                                    zip
                                    FROM reg_list WHERE phone='$phone'");                
                 
if (!$result) {
  exit('<p>Error performing query: ' .
      mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($result)) {
          $first = $row['first'];
              $last = $row['last'];
              $dob = $row['dob'];
              $phone = $row['phone'];
              $ins = $row['ins'];
              $addy = $row['addy'];
              $city = $row['city'];
              $state = $row['state'];
              $zip = $row['zip'];
                           
echo "<p>Congrats $first! You are now registered.<p>";
}


$result = mysql_query("SELECT count(first) as total_users FROM reg_list");
$row = mysql_fetch_array($result);

$users = $row["total_users"];
$mins = $users*15;
$total1 = time()+$users*15*60;
$total = date("h:i:s", $total1);


print "<b><font face=\"Arial Narrow\" size=\"2\">Total Number on waiting list:</font></b>  <font size='4'><b>$users</b></font><br>&nbsp;<br>";
print "<b><font face=\"Arial Narrow\" size=\"2\">Wait time:</font></b>  </font></b><font size='4'><b>$mins</b></font> minutes<br>&nbsp;<br>";
print "<b><font face=\"Arial Narrow\" size=\"2\">Your Appointment time:</font></b>  <font size='4'><b>$total</b></font>";



endif;
?>
0
 
radnorCommented:
I am assuming form 0900 until 2030, the form can be filled out???  You have the form working now, right?  Dont alter your form code.   Let this determine which page to display.



<?php

$server_to_local_time_offset = '0300';

$tod = (date('Hi')+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 900)) {
     header('SORRY_CLOSED.htm');     // edit this for your evening page
} else {
     header('FORM.PHP');          // edit this for your day page
}
?>
0
 
RaMb0z0Author Commented:
My form works fine. And your code seems like it should work, but I can't figure where to put this code in order for it to execute first.
0
 
radnorCommented:
I dont know the layout of your site....  But if you have a button that calls your form, replace that with my code and in my code place your form page call.

If your CURRENT page is like this (let's assume it is form.php):
<a href='form.php'>Fill out my form</a>

Change it to:
<a href='radnor.php'>Fill out my form</a>   <---  call it whatever you wish!

and the code "radnor.php" wold be:
<?php

$server_to_local_time_offset = '0300';

$tod = (date('Hi')+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 900)) {
     header('SORRY_CLOSED.htm');     // edit this for your evening page
} else {
     header('form.php);          // <-----  your ORIGINAL form page
}
?>
0
 
RaMb0z0Author Commented:
If I read that right you are saying to do this, but this isnt working either.

<a href="<?php

$server_to_local_time_offset = '0000';

$tod = (date("H:i:s")+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 1330)) {
     header('index.php');     // edit this for your evening page
} else {
     header('register.php?addpatient=1');          // edit this for your day page
}
?>"><img src="img/reg.jpg" alt="Pre-Register" width="83" height="82"  /></a><br />
  Pre-Register</p>
0
 
radnorCommented:
OK, I need a little info here.....

On your HOME page, I am assuming the call to register is: <a href="register.php?addpatient=1">(some text here to register)</a>

What is the NAME of your after hours page???

Care to give a URL???
0
 
RaMb0z0Author Commented:
Right now I am running this on a local server, and you are right about how i call to register.
Haven't made an after hours page yet...just using the home page for that right now.
0
 
radnorCommented:
*********************

copy an paste this as "tod.php"  (time of day)

*********************

<?php

$server_to_local_time_offset = '0300';

$tod = (date('Hi')+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 900)) {
     header('closed.htm');
} else {
     header('register.php?addpatient=1');
}
?>

*********************

copy and paste as "closed.htm"

*********************

<html>
<head>
<title>Try again later</title>
</head>
<body>
Sorry, but you can only REP REGISTER between the hours of 9:00AM and 8:30PM<br />
Please try again during those hours.
</body>
</html>


*********************

And in your HOME page, change the link to your register.php to this:
<a href='tod.php'><img src="img/reg.jpg" alt="Pre-Register" width="83" height="82"  /></a>



I am assuming you are using the "img/reg.jpg" as a link to pre-register.  OK, so this will display the image BUT instead of going to "register.php" it will go to TOD.PHP and look at the time of day.  If it is between 9am and 830pm, it will go to "register.php?addpatient=1 like in your EXISTING link????  If it is outside of those hours, tod.php will redirect the visitor to "closed.htm"  Where they will be instructed to come back between the 9am and 830pm.

Also, BE CAREFUL!!!!  Dont know what OS your serving.  But, *NIX (unix/linux) IS case sensitive!!!  M$ is not.
0
 
radnorCommented:
YUCK, I have a few tyops....  "REP REGISTER" s.b. "PRE REGISTER".....  But, sure you would have seen it!
0
 
RaMb0z0Author Commented:
Hmmm...its just staying on the tod.php page

<html>
<title>Time of Day</title>
</head>
<body>
<?php

$server_to_local_time_offset = '0000';

$tod = (date("H:i:s")+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 1430)) {
     header('closed.htm');     // edit this for your evening page
} else {
     header('register.php?addpatient=1');          // edit this for your day page
}
?>
</body>
</html>
0
 
radnorCommented:
Oh POOH!!!!  You are correct!!  Sorry fix tod.php with:
     header('Location: closed.htm');     // I forgot (Location:)  <------


<html>
<title>Time of Day</title>
</head>
<body>
<?php

$server_to_local_time_offset = '0000';

$tod = (date("H:i:s")+$server_to_local_time_offset);

if (($tod >=2030) || ($tod <= 1430)) {
     header('Location: closed.htm');     // edit this for your evening page
} else {
     header('Location: register.php?addpatient=1');          // edit this for your day page
}
?>
</body>
</html>
0
 
RaMb0z0Author Commented:
Works great!! Thank you sooo much!!
0
 
radnorCommented:
Just remember in tod.php YOU listed, one time is set for 2:30PM  ($tod<=1430)  That looks like the only change you'll need to make.

Glad to help!!!

Enjoy
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now