Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1621 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Timezone in PHP

Thread title: Timezone in PHP
Closed Thread    
    Thread tools Search this thread Display Modes  
09-20-2008, 08:24 AM
#1
PHP_Newbie is offline PHP_Newbie
Status: I'm new around here
Join date: Sep 2008
Location:
Expertise:
Software:
 
Posts: 1
iTrader: 0 / 0%
 

PHP_Newbie is on a distinguished road

  Old  Timezone in PHP

Hello,

What is the best way of using PHP to get a users time-zone. Set the environment with a cookie, so the script reads that times zone if a cookie exists?

I was originally thinking of using javascript to grab the users time then passing it through php. Is that a good way?

THis is what I currently have;


PHP Code:
<script> 
         
        var newTime = new Date(); 
        var hours = newTime.getHours(); 
        document.cookie = 'hours=' + hours; 
         
    </script> 
         
          <?php 
            
echo $_COOKIE['hours']; 
           
?>

09-26-2008, 02:48 PM
#2
geforce is offline geforce
Status: Member
Join date: Jul 2006
Location: UK
Expertise: Programming - PHP & MySQL
Software: Photoshop and Notepad++
 
Posts: 216
iTrader: 2 / 100%
 

geforce is on a distinguished road

Send a message via AIM to geforce

  Old

Hi,
You can set cookies through PHP if you want too. Id recommend using PHP to set your cookie because mine uses php to get timezone.

The best way to do this would to have the user select their timezone. Something like this:

PHP Code:
<?php

if( isset( $_COOKIE['timezone'] ) )
 {

  
$timezone $_COOKIE['timezone'];

 }
else
 {

  if( isset( 
$_POST['set_timezone'] ) )
   {

    
setcookie'timezone'$_POST['timezone'], ( time( ) + 3600000 ) );

   }
  else
   {

  echo 
'<form action="post" action="' $_SERVER['PHP_SELF'] . '">
          Select your timezone: <select name="timezone">

          </select>
          <input type="submit name="set_timezone" value="Set Timezone" />
          </form>
         '
;
   }

 }
?>
I haven't tested the above code but it should work.

Closed Thread    


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

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed