TIME BASED URL REDIRECT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JBAVINGTON
Forum Newbie
Posts: 3
Joined: Mon Aug 07, 2006 6:59 am

TIME BASED URL REDIRECT

Post 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
Last edited by JBAVINGTON on Mon Aug 07, 2006 7:41 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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');

?>
JBAVINGTON
Forum Newbie
Posts: 3
Joined: Mon Aug 07, 2006 6:59 am

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
JBAVINGTON
Forum Newbie
Posts: 3
Joined: Mon Aug 07, 2006 6:59 am

Post by JBAVINGTON »

thanks for that it works excellently thanks for all your help i will be back soon no doubt

thanks again
Post Reply