Time Base Redirect


#1

Is it possible to to time based website redirect?

Suppose I want show user can visit my page from 06:00AM to 12:00PM then after it any visit the page it will direct redirect to (timeout.html)

I search on Google in - (JS | .Htaccess) but there I not found.

Have you idea ?


#2

I think I'd be more inclined to use PHP for this.


#3

Is php help for this?
I use htacess . Will it work?

RewriteEngine On
RewriteCond %{TIME_HOUR}%{TIME_HOUR} >2109
RewriteRule ^$ /retail/dashboard.php [R=301,L]

#4

Try it and see!


#5

I use PHP, But why this is not working?

<?php
$time = date('G'); //24 hour without leading zeroes

if($time >= 9 && $time <= 9)         
$loc = 'good.php';

else if($time >= 21 && $time <= 3)    
$loc = 'bad.php';

else if($time >= 3 && $time <= 5)    $loc = 'sleep.php';

if(isset($loc)) {
    header("Location: https://abcd.com/{$loc}");
    exit;
}
?>

#6

Not working..Time waste@@


#7

Some of your conditions make no sense and the syntax is wrong.

Always use error reporting when testing php to find errors quickly. Though I expect this advice to go the same way as the multiple times you have been advised to use the validator to identify errors in your html syntax, in which case you are refusing to be helped and thus cannot be helped.


#8

Did you means I Validate this php on "W3VALIDATOR"

<?php
$time = date('G'); //24 hour without leading zeroes
if($time >= 9 && $time <= 9)
$loc = 'good.php';
else if($time >= 21 && $time <= 3)
$loc = 'bad.php';
else if($time >= 3 && $time <= 5) $loc = 'sleep.php';
if(isset($loc)) {
header("Location: https://abcd.com/{$loc}");
exit;
}
?>

After again validation it not working and not redirect..

Why?


#9

if($time >= 9 && $time <= 9)

This will only be true when $time is equal to 9. I doubt this is what you mean.


#10

That validator of for html. Use if on your html.
For php enable error reporting. It can be configured to display errors on screen in a development environment, or can log errors to a file on a live server.
Any errors and warnings are identified when the script is run. This is essential in debugging and development, you are stumbling around in the dark without it.


#11

...And when can a value be greater than 20 and less than 4?


#12

9=9 it was by mistake...

I want create ...Like;
From 09AM to 09PM=good.php
From 09PM to 03AM=bad.php
From 03AM to 06AM=sleep.php

Now you can understand what I want saying..


#13

Thank you for focus.
But when I correct it nor working..


#14

What does your corrected code look like?


#15

<?php
$time = date('G'); //24 hour without leading zeroes
if($time >= 9 && $time <= 21)
$loc = 'good.php';
else if($time >= 21 && $time <= 3)
$loc = 'bad.php';
else if($time >= 3 && $time <= 8) $loc = 'sleep.php';
if(isset($loc)) {
header("Location: https://website.com/{$loc}");
exit;
}
?>

I replaced the 9
And then put it in page but now it not working ..


#16

When you post code on the forums, you need to format it so it will display correctly. You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don't have that character.


#17

Actually I am new on sitepoint I not have knowledge very how to use and what is the purpose of fa-fa icons inside textarea when I creating a post.

Whatever Could you help..On this topic..


#18

Basic syntax - you forgot the curly braces around the if/else statements.


#19

Not understand..
Suggestions is better then practice


#20

There was a suggestion that you enable PHP error reporting.
Did you do that?