Time Base Redirect


#43

Don't be confused, think about what the logic needs to be.

If "time" - however that is expressed, eg. string, int, etc. is "something" then "do this".

The "something to something" suggests you want a "between".
In code, "between" is typically written as a "greater than this and less than that".

I find that once I can write something in non-code English so it makes sense and looks OK I can write the code for it more easily. Give that a try (writing the logic in non-code) and see how you do.


#44

I am confused in greater than and less then.

Ok..If change from G to A rhen it will might help us.


#45

It is explained here:-
http://php.net/manual/en/language.operators.comparison.php

No, I think G is best in this scenario.
http://php.net/manual/en/function.date.php


#46

Working with dates / times can be confusing. What looks "best" for humans is infrequently what's best for code.
For example, if I see something like a timestamp of "6783984608" it means next to nothing to me. I prefer either American or computer style like "Mar 17, 2018" or "2018-03-18"

I find it works best to accept input in "human" format, change it to "code" format" and use that until the code processing is done, and then changing it back to "human" format to display it.

AFAIK, timestamp format (data type integer) is the most efficient, but computer style (data type string) works well too as long as documentation is checked to make sure the code doesn't contain "gotchas".(for example, if a month with 30 days is compared to a month with 31 days then something you might not expect will happen)


#47

Really I changed the the again and again but it not be done and in proper manner as I want.

What I do for


#48

I too;


#49

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

if($time >= 9 || $time <= 21)         
$loc = 'start.php';

else if($time >= 21 || $time <= 9 )    
$loc = 'stop.php';


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

It not work only start.php shows. I want
Show : 09am to 9pm= start.php
And 09pm to 09am = stop.php


#50

It was only ONE of the if clauses that needed the AND changing to OR, not all of them.


#51

I use this php too but it not working fir redirect time based...
Why? Where is the issue~

<?php
/**
* Get URL to redirect to based on time of day
* call with no arguments to use current time, or
* pass in 24 hour number representing hour to test for different times
* Requires >= PHP7.0. For older versions change the '$hour = $currentHour ??...' line below
*/
function timeOfDayRedirection($currentHour = null) {
  
  $hour = ($currentHour) ? $currentHour : (int)date('G');
    
  //9am - 8:59:59pm
  if($hour >= 9 AND $hour <= 20) {
      return 'https://start-website.com';
  }
  
  //3am - 8:59:59am
  if($hour >= 21 AND $hour <= 8) {
      return 'https://sleep-website.com';
  }
  
redirect( timeOfDayRedirection() );
exit;

#52

How can $hour ever be greater than or equal to 21 AND less than or equal to 8?

Edit: By the way, AND and && are different ways of writing the same thing; OR and || are different ways of writing the same thing.


#53

If you Know where is the issue them why you not correct it..
Suggestions-suggestion my god are you not tried?


#54

You should really try to understand the suggestions they are giving you, and try to correct it yourself. The whole point is for you to learn.


#55

The main issue is I am not getting proper your language. Yes you write in english but me and your english is too different. That why I don't try which you saying..


#56

I'm sure language is part of the problem, but the main problem is that you are trying to do some very complicated things when you don't have a good grasp of the basics. You need to learn to walk before you try to run.


#57

Use your real website URL, so people can actually see real code being generated.


#58

I use not work


#59

How does that help when the problem is a PHP code issue?


#60

OK, another way to think of it. Look at this line of code:

if($hour >= 21 AND $hour <= 8) {

Now, forget about this being an hour, and just think about it being a number. So we're not talking about "before" and "after", but exactly what the code says, "greater than" and "less than". Now think of whether it's possible to have a number that is both larger than 21, and less than 8, at the same time.


#61

Hmm. does PHP do string theory yet?

Anyway, having the numbers split to where they correspond to where humans split the hours of a day will mean that slightly more verbose conditionals will be needed. Working with "24 hour time" instead of 12 hour AM and PM, will make it a bit easier without a "noon" split, but you will still need to deal with the "midnight" split.

For example, you can't have a third shift as 2300 to 0700, it would need to be 2300 - 2400 and 0000 - 0700


#62

I thinking : 09:00PM - 08AM :banghead: