PHP Timezone


#1

I just moved over to Dreamhost. So far, everything is going great. I hit one snag though.

I’ve followed the Wiki instructions for changing the timezone for scripts. However, this won’t work with PHP files, correct?

Here’s the code I’m using to display different images based on time of day:

<img src="http://hostname.com/picture<?php
$now = getdate();
$hour = $now[‘hours’];
$weekday = $now[‘wday’]; // 0 = Sun, 6 = Sat
if ($hour >= 21 && $hour < 24 && $weekday >=2) {
$timepic = ‘image01’;
} elseif ($hour >= 0 && $hour < 3 && $weekday >=2) {
$timepic = ‘image02’;

…ETC…
}
echo $timepic;
?>.jpg" alt=“Image Name” />

Obviously, I edited out some of that code just for demonstration purposes here on the forum.

Anyway, I’ve updated the htaccess file but the image display doesn’t change. I tried adding $timezone = ‘America/New_York’; to the code (before $now = getdate():wink: but that didn’t do the trick.

I ended up adjusting the times for each image to match west coast time, but this could get confusing when I make changes in the future. Which isn’t a big deal. I’m just hoping that there’s an easier way to set the timezone.

Thanks!


#2

do you know the time difference? If so, you can try this when everything fails.

$timedif = “+8”; // hours
$now = getdate(strtotime("$timedif hour"));

This will be a manual way to correct the time.

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


#3

You can change the timezone using your .htaccess file:

It’s working great for me.

Jan

Promo-Code: [color=#CC0000]SAVEMONEY97[/color] - Save [color=#CC0000]$50[/color] on your first year of hosting.
Get more promo codes here


#4

As I mentioned in my first post, the tip in the Wiki doesn’t work for me.

I’ll try the script edit that patricktan recommended and see what happens.


#5

That did the trick. Thanks patricktan! :slight_smile:


#6

Yeah! At least we get it worked!

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here