codrgi Posted April 15, 2009 Share Posted April 15, 2009 How am i able to make a PHP event, like say i wanted a php script to do something at 6PM and then stop at 8PM, how am i able to do this? Quote Link to comment Share on other sites More sharing options...
alphanumetrix Posted April 15, 2009 Share Posted April 15, 2009 I'm not entirely sure what you'd need that for. Maybe try this: time_sleep_until(); // makes the script sleep until specified timestamp set_time_limit(); // limits the maximum execution time in seconds --- edit: unless you mean something like give a user an option during a specified time of day or something. then i'd say set time options with if/else statements maybe. i'm not sure how to set that up off the top of my head, but i could look it up if someone else doesn't suggest a way first. Quote Link to comment Share on other sites More sharing options...
Carth Posted April 15, 2009 Share Posted April 15, 2009 I think you should set up a cron job on your server. Is it Linux and can you SSH to it? Edit: I may have misunderstood what you want to do... I thought you wanted to schedule when your script should run, such as a backup script. But maybe you wanted to limit the times when someone can access a PHP script. If you could clarify... Quote Link to comment Share on other sites More sharing options...
codrgi Posted April 15, 2009 Author Share Posted April 15, 2009 unless you mean something like give a user an option during a specified time of day or something. then i'd say set time options with if/else statements maybe. i'm not sure how to set that up off the top of my head, but i could look it up if someone else doesn't suggest a way first. That's what this is for, how am i able to make this php script show at just 6PM and then disapear at 8PM? thanks for your fast reply. Quote Link to comment Share on other sites More sharing options...
laffin Posted April 15, 2009 Share Posted April 15, 2009 use a redirection header. and some time/date functions to figure out the hr <?php // @(#) $Id$ // +-----------------------------------------------------------------------+ // | Copyright (C) 2008, http://yoursite | // +-----------------------------------------------------------------------+ // | This file is free software; you can redistribute it and/or modify | // | it under the terms of the GNU General Public License as published by | // | the Free Software Foundation; either version 2 of the License, or | // | (at your option) any later version. | // | This file is distributed in the hope that it will be useful | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // +-----------------------------------------------------------------------+ // | Author: pFa | // +-----------------------------------------------------------------------+ // function nl($str) { echo "{$str} <BR />\n"; } nl( $time=strtotime(date("H:i"))); // Current Hour nl( $window_start=strtotime(date('07:00'))); // Window Open At nl( $window_close=strtotime(date('11:00'))); // Window Closes At if($time < $window_start || $time > $window_start) { header("HTTP/1.1 503 Service Temporarily Unavailable"); header("Status: 503 Service Temporarily Unavailable"); die(); } echo "Welcome, please login"; ?> Quote Link to comment Share on other sites More sharing options...
Zane Posted April 15, 2009 Share Posted April 15, 2009 $t = date("G"); if($t >= 18 && $t else echo "The page is no longer available"; ?> using the same header idea this should do exactly what you want Quote Link to comment Share on other sites More sharing options...
codrgi Posted April 16, 2009 Author Share Posted April 16, 2009 <?php $t = date("G"); if($t >= 18 && $t <= 20) echo "The page is available"; else echo "The page is no longer available"; ?> using the same header idea this should do exactly what you want Thanks alot, this worked, however how do i make the time only server side? Quote Link to comment Share on other sites More sharing options...
.josh Posted April 16, 2009 Share Posted April 16, 2009 what do you mean by "make the time only server side"? date draws from the server's clock. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted April 16, 2009 Share Posted April 16, 2009 that is only server side, if this was done in javascript it would be client side Quote Link to comment Share on other sites More sharing options...
codrgi Posted April 16, 2009 Author Share Posted April 16, 2009 what do you mean by "make the time only server side"? date draws from the server's clock. Not when i tried it, i have 2 comps, and put the clock back on my laptop for testing purposes, the laptop is not connected with the server, just for viewing and it showed the event when it shouldn't have, is there any way to make it server side only? Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted April 16, 2009 Share Posted April 16, 2009 date() is server side, if your pc is the testing server then the date() you get will be the same as your pcs. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted April 16, 2009 Share Posted April 16, 2009 Not when i tried it, i have 2 comps, and put the clock back on my laptop for testing purposes, the laptop is not connected with the server, just for viewing and it showed the event when it shouldn't have, is there any way to make it server side only? I think you need to read what you just said. If the laptop is not the server, then nothing changed relative to your script. I lold. Quote Link to comment Share on other sites More sharing options...
.josh Posted April 16, 2009 Share Posted April 16, 2009 If you run the script ON your laptop (like with wamp or something), then your laptop IS the server, so it's using your laptop's clock. php is a server-side language. It parses the script and sends the results to the client. To see what I mean, load the page up in your browser, rightclick and view source. You will not see the php script as you would with javascript. Quote Link to comment Share on other sites More sharing options...
codrgi Posted April 16, 2009 Author Share Posted April 16, 2009 date() is server side, if your pc is the testing server then the date() you get will be the same as your pcs. That's wierd...i added the date("G") but when i try on my other pc - not connected in anyway with my server, and turn the clock on it back to the time of the event, it shows the event when it shouldn't. ??? Not when i tried it, i have 2 comps, and put the clock back on my laptop for testing purposes, the laptop is not connected with the server, just for viewing and it showed the event when it shouldn't have, is there any way to make it server side only? I think you need to read what you just said. If the laptop is not the server, then nothing changed relative to your script. I lold. I never said anything about a script changing. If you run the script ON your laptop (like with wamp or something), then your laptop IS the server, so it's using your laptop's clock. php is a server-side language. It parses the script and sends the results to the client. To see what I mean, load the page up in your browser, rightclick and view source. You will not see the php script as you would with javascript. I'm relatively quite new to php, so i'll try and explain this a lil better . The laptop is separate from the server, the server is on a dedicated server, when i tried viewing the script on my home laptop the script didn't show due to the timed event, but when i turned my laptops clocks back at the time of the event, the php event was accessable. Quote Link to comment Share on other sites More sharing options...
.josh Posted April 16, 2009 Share Posted April 16, 2009 that's not possible. php cannot parse itself. you have to install the parser and have it running under something like apache or IIS in order for the script to execute. Quote Link to comment Share on other sites More sharing options...
codrgi Posted April 16, 2009 Author Share Posted April 16, 2009 It now appears to be working, ty all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.