Log in

View Full Version : redirect once at certain time?



lankinator
04-13-2007, 07:29 PM
How would i create a script that would take a user to a page at a certain time and wouldn't take them there again until the next day at the same time?

Thanks

thetestingsite
04-13-2007, 07:33 PM
May need some modification, and it is not tested.



<?php

$redirect_Start = "1400"; //don't redirect before 2pm
$redirect_End = "1500"; //don't redirect after 3pm

$redirect_To = "redirect.php"; //where to redirect to

if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {

header('Location: '.$redirect_To);
}

else {
//whatever you want
}
?>


Hope this helps.

//EDIT: new addition to code is not tested Modifications are in red. Let me know if it doesn't and I will work on fixing it.

djr33
04-13-2007, 11:34 PM
That would work, I think, but why would you redirect at only exactly 2pm?
That would only do it for that specific time. I guess it might do the whole hour, but I'm not sure.
I'd think a range would be better, or just "after 2pm", etc.

thetestingsite
04-13-2007, 11:36 PM
Yea, that script will only redirect a user at 2pm (not 2:01 or 1:59, but 2pm on the dot). I was working on adding to it, but went to lunch and this slipped my mind. Thanks for bringing this back up, djr33.

djr33
04-13-2007, 11:41 PM
This should work... change as needed--

<?php

$redirect_Time = "1400"; //redirect at 2pm
$redirect_Flex = "30"; //.5hr flexiblity (1:30-2:30)
$redirect_To = "redirect.php"; //where to redirect to

if (date('Gi') >= $redirect_Time-$redirect_Flex && date('Gi') <= $redirect_Time+$redirect_Flex) {

header('Location: '.$redirect_To);
}

else {
//whatever you want
}
?>

lankinator
04-14-2007, 12:19 PM
i have a problem with "tts" code:

<?php

$redirect_Start = "1300"; //don't redirect before 8pm
$redirect_End = "1400"; don't redirect after 9pm

$redirect_To = "javascript:buildtimeP()"; //where to redirect to

if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {

header('Location: '.$redirect_To);
}

else {
//whatever you want
}
?>

it says there is a problem with the:

if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) { part.

thetestingsite
04-14-2007, 02:19 PM
The only thing I can see with the code you posted is an uncommented line:



<?php

$redirect_Start = "1300"; //don't redirect before 8pm
$redirect_End = "1400"; //don't redirect after 9pm

$redirect_To = "javascript:buildtimeP()"; //where to redirect to

if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {

header('Location: '.$redirect_To);
}

else {
//whatever you want
}
?>


The part in red is what needs to be added, other than that the code should work fine.
Hope this helps.

Twey
04-14-2007, 02:45 PM
I don't believe you can redirect to a javascript: pseudo-URL in a Location header.

mburt
04-14-2007, 03:08 PM
Yes, I think that's only an anchor property... I'll test it though.

mburt
04-14-2007, 03:11 PM
Hmm. Type this into your url:

javascript:alert(typeof window);
Seems to work.

Twey
04-14-2007, 03:44 PM
I know it works when typed into the address bar (although not in Konqueror, as it happens), but javascript: is a pseudo-URL scheme, not a real one, so it's invalid in Location headers.