I am creating a form with a date field. i want the date field to autofill onload. The form will then be submitted to a database. My question then, is should I auto fill the date with JS from the users computer, or with PHP from the server that contains the DB, where the report will be stored?
If my question makes no sense, let me know because i am still pretty new to web coding.
Thank you.
Should I create date function with JS or PHP
Page 1 of 15 Replies - 655 Views - Last Post: 27 April 2011 - 06:14 AM
Replies To: Should I create date function with JS or PHP
#2
Re: Should I create date function with JS or PHP
Posted 26 April 2011 - 01:50 PM
Well, it depends. What is the purpose of this date? and what is it used for on the page?
#3
Re: Should I create date function with JS or PHP
Posted 26 April 2011 - 01:58 PM
always bear in mind that JS may be disabled, so at least PHP will have to do a check on the input.
#4
Re: Should I create date function with JS or PHP
Posted 26 April 2011 - 02:00 PM
If the form has a date field, then I am assuming that they have the option of entering a date ?
So that would seem to suggest that the client's date is what you want.
This really comes down to the requirements of your application though. What is the date used for ? Is the intention to be the date of the client? or is it important for it to be the date of the server.
For example. User is in California, server is in New York. User is 3 hours behind the server.
If the date is essential in deciding if the order should be placed by a deadline EST(New York Time zone), then that date saved better be based on the server. Right ?
In general though, if you want all data on the server to be consistent -- you should be using server time and converting to the user's time zone on the client side if appropriate.
So that would seem to suggest that the client's date is what you want.
This really comes down to the requirements of your application though. What is the date used for ? Is the intention to be the date of the client? or is it important for it to be the date of the server.
For example. User is in California, server is in New York. User is 3 hours behind the server.
If the date is essential in deciding if the order should be placed by a deadline EST(New York Time zone), then that date saved better be based on the server. Right ?
In general though, if you want all data on the server to be consistent -- you should be using server time and converting to the user's time zone on the client side if appropriate.
This post has been edited by Prototypical: 26 April 2011 - 02:01 PM
#5
Re: Should I create date function with JS or PHP
Posted 26 April 2011 - 09:38 PM
Thinking about it, i decided to create a date function in js. This is just local info being stored on a local server, so even if the times are not 100% sync'd, I think it will be close enough. Thank you all.
#6
Re: Should I create date function with JS or PHP
Posted 27 April 2011 - 06:14 AM
Prototypical, on 26 April 2011 - 05:00 PM, said:
...
In general though, if you want all data on the server to be consistent -- you should be using server time and converting to the user's time zone on the client side if appropriate.
In general though, if you want all data on the server to be consistent -- you should be using server time and converting to the user's time zone on the client side if appropriate.
The client side date won't always be right and you as a programmer's got no control over that. As the other guys stated it all comes down to what you want to do. Displaying a clock on a user page would be more feasible if you used client side time (sending a request to the server every second for the time is a no no). Other things like login timestamp etc...should use server time.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote





|