Jump to content


Php time


6 replies to this topic

#1 Latinoking

    Young Padawan

  • Members
  • Pip
  • 18 posts
  • Gender:Male
  • Location:Germany

Posted 03 September 2007 - 02:25 PM

I would like to know if its possible to make script that will work only limited time. For example I have poll on my web page but like to make it active only, for example, from 8:00 till 18:00.

#2 Balor

    PHP Nerd

  • Members
  • Pip
  • 63 posts
  • Gender:Male
  • Location:Germany->Frankfurt
  • Interests:My beautyful girl, my son and webcoding. I'm also very interested in art but I'm not really good at art... it's sad but true ^^

Posted 03 September 2007 - 02:35 PM

Sure! You should look into one of my tutorials. The time calculation uses everything you need for your script.

#3 Matt L

    Young Padawan

  • Members
  • Pip
  • 272 posts
  • Gender:Male
  • Location:Newcastle

Posted 03 September 2007 - 02:39 PM

Should work. Haven't tested this but try:

<?php
$time = time('h'); //not sure about this bit, haven't used time function in a LONG time
if($time > "8" || $time < "18") { // If this doesn't work, try taking the " out
	// Your script here
	}
else {
	echo("Sorry! The script is offline");
	}

In theory that should work. Someone'll correct me if I'm wrong. I would test it but Dreamweavers playing up for me and I don't like using notepad.

#4 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 03 September 2007 - 02:40 PM

yup ofcourse. e.g. a script that will work fo the next hour:
<?php

$current_time = time();
$time_to_stop = 1188859896
if($current_time < $time_to_stop){

 //script goes here

}else{

 print "Sorry, you've missed it";

}
?>

another way to get the time to stop could be strtotime("08:00:00 10 September 2000");
Anyway, you need a timestamp in that form

#5 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 03 September 2007 - 02:44 PM

View PostMatt L, on Sep 3 2007, 09:39 PM, said:

Should work. Haven't tested this but try:

[code]<?php
$time = time('h'); //not sure about this bit, haven't used time function in a LONG time
You're looking for: date("h") :)

#6 Latinoking

    Young Padawan

  • Members
  • Pip
  • 18 posts
  • Gender:Male
  • Location:Germany

Posted 04 September 2007 - 02:09 PM

And one more question about time. Is there way to make script that will auto load at particular time ?

#7 .CJ

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Gender:Male
  • Location:Leeds, UK

Posted 04 September 2007 - 03:28 PM

I believe a Cron Job would be needed for this... check your cPanel.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users