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
Printable View
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
May need some modification, and it is not tested.
Hope this helps.Code:<?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
}
?>
//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.
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.
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.
This should work... change as needed--
PHP Code:<?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
}
?>
i have a problem with "tts" code:
it says there is a problem with the: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
}
?>
part.Code:if (date('Gi') >= $redirect_Start && date('Gi') <= $redirect_End) {
The only thing I can see with the code you posted is an uncommented line:
The part in red is what needs to be added, other than that the code should work fine.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
}
?>
Hope this helps.
I don't believe you can redirect to a javascript: pseudo-URL in a Location header.
Yes, I think that's only an anchor property... I'll test it though.
Hmm. Type this into your url:
Seems to work.Code:javascript:alert(typeof window);
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.