View Full Version : Getting the users time and not the servers

04-25-2004, 03:12 PM
So, I wrote this script

// Define some constants

// Create the image
$img_handle = ImageCreate(WIDTH,HEIGHT) or die("Image could not be created.");

// Define the background color
$background = ImageColorAllocate($img_handle, 255, 255, 255); // 255 255 255 is white

// Define the text color
$text = ImageColorAllocate($img_handle, 0, 0, 0); // 0 0 0 is white

// Set the date to a variable
$date = date("l, F j, Y - g:i.s a");

// Lets write the text
ImageString($img_handle, 2, 5, 5, $date, $text);

// Send the header and create the image
header ("Content-type: image/png");
ImagePng ($img_handle);
?> and everything works as expected, except for the fact that it shows the servers time, which is Central Standard and I am Eastern/GMT -5. So my question is, how can I make my script show the user who is viewing time instead of the servers? Thanks a lot,


04-25-2004, 04:14 PM
As far as i know, you need to use clientside scriptingto get the clients date-time. Or, like in this forum, you need to store the timezone that the client is ininside a cookie or db, after the entered that (on registration or whatever).

04-25-2004, 07:46 PM
I thought about the Javascript idea, but my problem was "How do I get JavaScript to interact with PHP?"

Thanks as always, raf!


04-25-2004, 08:38 PM
Well, you just compose the time-value and then store it inside a hidden formfield and then post the form to the server.