Getting date in client-side

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
BRk
Forum Newbie
Posts: 6
Joined: Sat Jul 26, 2003 3:02 pm

Getting date in client-side

Post by BRk »

Hi , since i'm not an expert in php or java could anyone tell me how to do something like this (takes the screen resolution):
<?php
if (isset($_GET['width']) AND isset($_GET['height'])) {
// output the geometry variables
echo "Screen width is: ". $_GET['width'] ."<br />\n";
echo "Screen height is: ". $_GET['height'] ."<br />\n";
} else {
// pass the geometry variables
// (preserve the original query string
// -- post variables will need to handled differently)

echo "<script language=\"javascript\">\n";
echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
. "&width=\" + screen.width + \"&height=\" + screen.height;\n";
echo "</script>\n";
exit();
}
?>

but with the date an hour, this is because users have different time zone that the server, thanks :wink:
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

No need to use Javascript for this. Just use PHP's own Date and Time Functions.
BRk
Forum Newbie
Posts: 6
Joined: Sat Jul 26, 2003 3:02 pm

thanks, but....

Post by BRk »

Thanks for the reply but I just can' t do that because of the GMT time zone because the server is in the other side of the world so the hour isn't the same, that's why I need a client-side programing language...
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

gmstrftime() was created exactly for that purpose.
Use it together with $_SERVER["HTTP_ACCEPT_LANGUAGE"] - make sure register_globals is on (if in doubt read sticky announcement in "PHP Normal" (at the bottom)).
BRk
Forum Newbie
Posts: 6
Joined: Sat Jul 26, 2003 3:02 pm

Post by BRk »

Thanks, the information that you just gave me save me like 4 hours of work!YEah!
Patrik, u RULE!
Post Reply