Link to home
Start Free TrialLog in
Avatar of RaMb0z0
RaMb0z0

asked on

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.
Avatar of RaMb0z0
RaMb0z0

ASKER

Sorry i worded that wrong. I meant to say redirect the page between 8:30 pm and 9:00 am
Do you have PHP avail?  Or would you like a JS example?
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
}
?>
Avatar of RaMb0z0

ASKER

I am using php but java would be fine too.
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);

?>
Avatar of RaMb0z0

ASKER

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;
?>
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
}
?>
Avatar of RaMb0z0

ASKER

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.
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
}
?>
Avatar of RaMb0z0

ASKER

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>
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???
Avatar of RaMb0z0

ASKER

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.
*********************

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.
YUCK, I have a few tyops....  "REP REGISTER" s.b. "PRE REGISTER".....  But, sure you would have seen it!
Avatar of RaMb0z0

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of radnor
radnor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RaMb0z0

ASKER

Works great!! Thank you sooo much!!
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