Need help with redirecting a domain based on time of day

ppcgod

Registered Member
Joined
Feb 18, 2009
Messages
55
Reaction score
33
I have a domain that I want to redirect to site A between 7amEST-7pmEST and redirect conversely to site B from 7pm-7am. (hiding from someone lol) Right now I just have to log in and edit my meta refresh manually every day (gets quite annoying).
Is there a script to make it change redirect automatically based on a server side timing? I tried to gogle it but it was confusing sorry I am a noob with php and html helppp lol... or if anyone knows a good site to read up on this would help me too. i tried to goog the problem did not help much.
 
This will redirect them based on THEIR timezone. So if it's 7am-7pm their timezone then this is it. Adjust the code as needed depending on the timezone the visitor is in. This isn't the only way to do this though.

Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function ampmRedirect(dayURL, nightURL)
{
    var currentTime;
    var currentHour;

    // get the current date and time
    currentTime = new Date();

    // returns the hour in military time
    currentHour = currentTime.getHours();
    // check if the hour is between 6pm and 6am
    if ((currentHour < 7) || (currentHour > 19)) {
        window.location = nightURL;
    } else {
        window.location = dayURL;
    }
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
Click here to go to the next page:<BR>
<INPUT TYPE="button" VALUE="Next"
onClick="ampmRedirect('day.htm','night.htm')">
</FORM>
</BODY>
</HTML>
 
Last edited:
And you can do it in automatically PHP as well (off the top of my head, so this hasn't been tested):

Code:
<?php
   $hour = date('G');
   if ( $hour >= 7 && $hour <= 19 )   // If its between 7am and 7pm display site1.com
   {
      header("Location: http://site1.com");
   }
   else
   {
      header("Location: http://site2.com");
   }
?>
 
Ooops - forum said there was a problem with my posting - this is a dup.
 
Last edited:
Ooops - forum said there was a problem with my posting - this is a dup.
 
Last edited:
Fatboy do you have any idea how to redirect based on referr domain .tld ?

If the referrer tld is .com go site 1 else site 2

Thanks
 
Again, off the top of my head try something like:

Code:
<?php
   if ( strpos($_SERVER['HTTP_REFERER'], ".com"))   
   {
      header("Location: http://site1.com");
   }
   else
   {
      header("Location: http://site2.com");
   }
?>

If that doesn't work give me a shout and I will get on my laptop and figure it out :)
 
Very simple but effective, is working.
One more thing, how to add multiple TLDs or ccTLDs? if .com, .net, .co.uk ?
 
Drop me a PM and I will sort that out - its very easy :)
 
Sorry, was a bit late coming back to this one.
Try something like:

Code:
<?php
   if ( strpos($_SERVER['HTTP_REFERER'], ".com"))   
   {
      header("Location: http://site1.com");
   }

   if( strpos($_SERVER['HTTP_REFERER'], ".net"))
   {
      header("Location: http://site1.com");
   }

   if( strpos($_SERVER['HTTP_REFERER'], ".co.uk"))
   {
      header("Location: http://site3.com");
   }

?>

FB
 
Once again thanks for the help, the second function works as well. :D
 
Back
Top