Jump to content

How to make PHP event?


codrgi

Recommended Posts

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.

 

Link to comment
Share on other sites

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... :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";

?>

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  ;D

 

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 ;D.  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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.