www.webdeveloper.com
Results 1 to 3 of 3

Thread: PHP is displaying the wrong timezone

  1. #1
    Join Date
    Jun 2007
    Posts
    186

    PHP is displaying the wrong timezone

    Hello everyone,

    I have been through so many web sites looking for how I can output the date and time below in PST. It defaults normally to UTC time, but i want it in pacific time. Any ideas or help would be greatly appreciated. Thanks so much, Cedric

    Here is my code. This script (when accessed), will create a file and store the persons information in the file. It is a login script to keep track of people who login to the secure area of my site. It logs the time in UTC time and I would like to log it in PST time. I'm sure it's probably very easy...I'm just not quite sure how to do it.


    <?php
    define("DATE_FORMAT","d-m-Y H:i:s");
    define("LOG_FILE","log.php");
    $logfileHeader='
    <html>
    <body>
    <table width="1" height="15" border="0"><tr><td></td></tr></table>

    <table width="1000" border="0" align="center" cellpadding="0" cellspacing="1" class="ts4">
    <tr><th>Username</th><th>Date/Time (UTC)</th><th>IP Address</th><th>Hostname</th><th>Track</th></tr>'."\n";
    $userIp = (isset($_SERVER['REMOTE_ADDR']) && ($_SERVER['REMOTE_ADDR'] != "")) ? $_SERVER['REMOTE_ADDR'] : "Unknown";
    $hostName = gethostbyaddr($userIp);
    $actualTime = date(DATE_FORMAT);
    $username = $_REQUEST[uid];

    $logEntry = " <tr><td width=150>$username</td><td width=200>$actualTime</td><td width=125>$userIp</td><td>$hostName</td><td width=125><a href=http://www.dnsstuff.com/tools/ipall.ch?domain=$userIp>$userIp</a></td></tr>\n";

    if (!file_exists(LOG_FILE)) {
    $logFile = fopen(LOG_FILE,"w");
    fwrite($logFile, $logfileHeader);
    }
    else {
    $logFile = fopen(LOG_FILE,"a");
    }

    fwrite($logFile,$logEntry);
    fclose($logFile);
    ?>

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    One way would be top add the following line to the top of all the pages.

    PHP Code:
    <?php  putenv("TZ=America/Los_Angeles"); ?>
    If you have access to the php.ini you can do it easier by using the following in that file instead:

    Code:
    date.timezone = "America/Los_Angeles"
    Stephen

  3. #3
    Join Date
    Jun 2007
    Posts
    186
    thank you so much for your help...this worked perfectly!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles