Page 1 of 1

TIME BASED URL REDIRECT

Posted: Mon Aug 07, 2006 7:09 am
by JBAVINGTON
Hi All

i am pretty new to PHP so please bare with me im currently writing a website that has a call me now feature

what i want to do is place a link on the hompage that points to a script that wil retrieve the time and date from MY HOSTING SERVER not the users local server and if it is between monday and friday and the hours of 0900 and 1800 i want them to be directed to a page called support open.htm if the time is anything else to be redirected to a page called support closed.htm

i have been scouring the web but i have found nothing that helps i did find a html script that i have tested over the last couple of days but thats flaky at best

after reading thru this forum thought this would be the best place to look i am pretty desperate for this to be up and running as this is all thats left to do so i can launch the site

thanks in advance

jon

Posted: Mon Aug 07, 2006 7:20 am
by Chris Corbyn
Doesn't sound urgent.... usally placing "urgent" in the thread title makes it look like you just want priority and is often ignored so it's best not to do it.

Moving on...

You just need to check timestamps and then do a header redirect.

At the TOP of the page:

Code: Select all

<?php

$day = date('w');
$hour = date('H');

//If not saturday or sunday
if ($day != 0 && $day != 6)
{
    if ($hour >= 9 && $hour < 18)
    {
        header('Location: supportopen.html');
        exit();
    }
}

//If we got this far the desk is closed
header('Location: supportclosed.html');

?>

Posted: Mon Aug 07, 2006 7:29 am
by JBAVINGTON
apologies for my ignorance and thanks for the quick reply

but am i right in saying i just add the text you supplied to the <head> of the page or do i also need to add a PHP file aswell

not sure how i implement

thanks again

Posted: Mon Aug 07, 2006 7:43 am
by Chris Corbyn
JBAVINGTON wrote:but am i right in saying i just add the text you supplied to the <head> of the page or do i also need to add a PHP file aswell

not sure how i implement

thanks again
I wrote that file so you could quite literally save it as "support.php" with nothing but those contents... no HTML at all, just that code.

Then you'd have two files it redirects to: "supportopen.html" and "supportclosed.html".

You just need to point anyone wanting support to support.php and that file will send them off in the right direction.

Posted: Mon Aug 07, 2006 7:50 am
by JBAVINGTON
thanks for that it works excellently thanks for all your help i will be back soon no doubt

thanks again