Current location: Hot Scripts Forums » Programming Languages » PHP » Time Help


Time Help

Reply
  #1 (permalink)  
Old 09-17-05, 11:41 AM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Time Help

I want to restrict access to these links between 6pm and 6am
Here is what I have:
PHP Code:

echo "<div class='head'>Services</div>";

if(
$timcheck "6pm" || $timcheck "6am"){
     echo 
"<div class='content'><center><b>Forms are offline</b></center></div>";
}else{
     echo 
"<div class='content'><center><a href='signup.php?op=web'>Web Hosting</a><br>
<a href='signup.php?op=ts'>Teamspeak Hosting</a></center></div>"
;

and this doesn't work it always says Forms are offline can I make it so it only works off my timezone (-600)?
Reply With Quote
  #2 (permalink)  
Old 09-17-05, 02:42 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
how are you populating the variable $timcheck? because appearntly php is treating 6pm and 6am as "6" only!
if you want to make something depending on your own time zone, then use gmdate()
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 09-17-05, 04:11 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by NeverMind
how are you populating the variable $timcheck? because appearntly php is treating 6pm and 6am as "6" only!
if you want to make something depending on your own time zone, then use gmdate()
could some one teach me how to do that?
Reply With Quote
  #4 (permalink)  
Old 09-18-05, 08:21 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
still, you have not answered my question. how are you generating the time in your script?
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 09-18-05, 10:11 AM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
PHP Code:

$timcheck date("ha"); 

I think i should use military timeinstead of am/pm
Reply With Quote
  #6 (permalink)  
Old 09-18-05, 02:06 PM
Trevor's Avatar
Trevor Trevor is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Denver, Colorado
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Give this a try.


PHP Code:

$now date("G");
if((
$now 6) OR ($now 12)) {
 echo(
"<div class=\"content\" align=\"center\" style=\"font-weight: Bold;\">Forms are offline</div>\n");
} else {
 echo(
"<div class=\"content\" align=\"center\">");
 echo(
"<a href=\"signup.php?op=web\">Web Hosting</a><br /><a href=\"signup.php?op=ts\">Teamspeak Hosting</a>");
 echo(
"</div>\n");

By using the function date with a param of "G", you are asigning a "24-hour format of an hour without leading zeros". The only kicker is, this is the server time, which may not be your local time. If you server is in another timezone, you may have to adjust the 6 and 12 above.

Hope that helps. And sorry for the style change. I'm a bugger like that.
__________________
The Universe Our God, Nature Our Temple, Love And Duty Our Religion, Knowledge Our Happiness And Consolation, Death The Dissolution Of The Ego, And The Return To Eternity.
Reply With Quote
  #7 (permalink)  
Old 09-18-05, 05:02 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Trevor
Give this a try.


PHP Code:

$now date("G");

if((
$now 6) OR ($now 12)) {
 echo(
"<div class=\"content\" align=\"center\" style=\"font-weight: Bold;\">Forms are offline</div>\n");
} else {
 echo(
"<div class=\"content\" align=\"center\">");
 echo(
"<a href=\"signup.php?op=web\">Web Hosting</a><br /><a href=\"signup.php?op=ts\">Teamspeak Hosting</a>");
 echo(
"</div>\n");

By using the function date with a param of "G", you are asigning a "24-hour format of an hour without leading zeros". The only kicker is, this is the server time, which may not be your local time. If you server is in another timezone, you may have to adjust the 6 and 12 above.

Hope that helps. And sorry for the style change. I'm a bugger like that.
The only problem with that is the people in the uk or other side of the world will see if because the date(); function goes off thier computer not the server.
__________________
Connor Strandt
JCS Photography
www.JCStrandt.com
Reply With Quote
  #8 (permalink)  
Old 09-19-05, 08:10 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
The only problem with that is the people in the uk or other side of the world will see if because the date(); function goes off thier computer not the server.
that is not true..
PHP is server side and nothing executes in the user's end.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #9 (permalink)  
Old 09-19-05, 07:05 PM
connor connor is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Knob Noster, Mo
Posts: 228
Thanks: 1
Thanked 0 Times in 0 Posts
Well I can't get this to work eather i still need more help.
__________________
Connor Strandt
JCS Photography
www.JCStrandt.com
Reply With Quote
  #10 (permalink)  
Old 09-20-05, 02:41 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
what is your timezone from GMT?
and what is your server's timezone? when you print a regular date() what is the difference between the time displayed and your local time?
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change a dynamic object like time? LEN2884 C/C++ 0 05-27-05 04:55 AM
time adjustment dex002 PHP 2 05-09-05 12:50 PM
Reduce the time intensive phases of .Net application development using TierDeveloper3 smars General Advertisements 0 12-02-03 05:15 AM
Showing time is users time zone? Nasimov PHP 1 11-20-03 07:14 AM


All times are GMT -5. The time now is 06:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.