WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Local-to-user date and time display regardless of time zone or where the website's server is located
Categories : PHP, Date Time, HTML and PHP, Java Script Click here to Update Your Picture
Sea Ansley
Date : Mar 30th 2002
Grade : 2 of 5 (graded 7 times)
Viewed : 21524
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Sea Ansley
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

(I originally posted this in the main PHP manual some time in early 2002 and an
article outlining this amongst other things may soon circulate somewhere on u-
magazine.com or elsewhere.)

I used some help from the web as far as the javascript element goes, but the rest is
my own strange reasoning.

I learned everything the hard way when moving to a server that was out of our time
zone, and discovered that all of the posts in our message board were three hours
behind us. I also got in a bit of an argument with one of the main PHP.net guys
about why "simple" things like this should be more important than functions like
Output Buffering.

Anyhow,

<?
//first lets introduce the main page displaying the local-to-user date and time. As
//I was working on forums scripts, lets call this forums.php the way our forums are
//constructed is that all the programming is done, then the layout is compiled and
//parsed in one giant template, which is very fast.

//This is part of the programming before the page template is parsed. If the user
//time zone cookie hasn't been set (on the first visit to a page, it won't have
//been), open the javascript include that will appear in the page's template :

if(!$usertimezone){

// special amendment for date/time conversion
// open javascript template/include

$checktimezone=parsetemplate("checktimezone");

// this javascript looks like this:

/* <script type="text/javascript">
now = new Date();
window.location.href="$PHP_SELF?tz=" + now.getTimezoneOffset();
</script>
*/

// somebody else created the script above. It makes sense though, on the first visit
// to the page, it automatically redirects to the same page, with the time zone
// variable ("tz") passed through the URL.

}elseif($tz){

// the next time a page in the forums has been accessed, and the cookie has not yet
// been set, set a cookie with the user's time zone (from GMT) AND create a variable
// for the time zone, because data in a cookie won't be seen until the next header
// request, and you want everything to take effect NOW.

$usertimezone=$tz;
setcookie("usertimezone",$usertimezone);

}

// next page is your functions page
// user date/time with local time zone

function userdate($format,$timestring){

// declare globals (that being the cookie and variable you have set)

global $usertimezone;

// convert user time zone into seconds

$timezone=$usertimezone*60;

// find timezone difference between server and UST in seconds

$difference=date("Z");

// difference between user and server

$usertime=$timestring-$difference-$timezone;

// return new value

return(date($format,$usertime));
}

// end user date/time
// then, when you want to display the date and time local to the user, you call it
// like this, just like you would a normal "date()" function, but allowing for the
// new function you have just created (assuming you used a time() string for your
// date):

$posttime = userdate($your_date_format,$time_of_post);

// I'm not sure why there isn't some way to read the time/date headers in a page
// request from the user's browser like you do with everything else in the language,
// compare that to the server's time, and exclude client-side programming
// altogether. If you can figure out a user's IP address, browser type and credit
// card number, you can certainly figure out the difference between their time and
// the server's.

// I have been using this date/time setup for a couple of months now, and to be
// honest, I had forgotten we even used it. This is a good thing, because at first I
// assumed it would all be a bit too distracting or annoying, but I was far wrong.



PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS
This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time.
Categories : PHP, Calendar, Date Time, HTML and PHP
OverEasy - PHP generated JavaScript to do mouseovers on your pages. Modify one file and one function does it all for you!
Categories : PHP, Java Script, HTML and PHP, MySQL
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
Tree Menu Dynamic (+Static) with Loading in Progress..
Categories : PHP, Java Script, HTML and PHP
Website colour changer
Categories : PHP, HTML and PHP, Date Time
Calendar using Date function
Categories : HTML and PHP, PHP, Date Time, Calendar
CALENDAR - easy calendar-navigation with PHP
Categories : PHP, Date Time, HTML and PHP, Calendar
Remote Scripting: send form POST data to a script and insert the results into a page without refreshing the page.
Categories : PHP, AJAX, HTML and PHP, Java Script
PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions
Local Time clock and Server time usign PHP and JavaScript
Categories : PHP, Java Script, Date Time, Beginner Guides
Simple PHP control CSS Calendar
Categories : PHP, HTML and PHP, Calendar, Date Time, CSS
Dynamic Calendar in PHP, Javascript and HTML.
Categories : PHP, Java Script, HTML and PHP, Calendar
Dynamic generation of textboxes, select items etc in a table for use with databases applications, matrimonials and for job sites
Categories : PHP, HTML and PHP, Java Script
Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps.
Categories : HTML and PHP, PHP, MySQL, Date Time