NYCPHP Meetup

NYPHP.org

[nycphp-talk] Client vs. Server programming

tedd tedd at sperling.com
Thu Sep 21 18:36:21 EDT 2006


At 2:37 PM -0700 9/21/06, LK wrote:
>Hello,
>
>I've spent some time developing proficiency in JavaScript and AJAX. Every time
>I try to go to the server PHP programming, I end up scratching my head asking
>why would anybody program on the server?
>
>Take form validation, for example. A user registers to a service for the first
>time and fills out a registration form. I need to check if the Username is
>already taken by someone else. In the JavaScript/AJAX framework the form and
>the entire page is available thru the DOM, and I just have a simple query.php
>script running on the server to execute queries and send back the result. I
>construct the query and AJAX it over to the query.php. If a record with the
>same username is found, I alert("...") the user to try it again. The original
>form remains on the screen without change. The deal is done.
>
>Not so with the server side programming. The form is submitted to a
>process_form.php. Then, if the username already exists in the database, the
>script has to rebuild the original form with the previous values filled in by
>copying user inputs from the $_POST array back into the HTML for *each* input
>field with <?php echo $_POST[] ?>, not to mention session state and other
>housekeeping. That seems like a lot of work to implement something so simple.
>
>So what are the advantages of server programming? What what am I missing?
>
>Thanks
>
>Leo Kokin

Leo:

1. Security --  javascript provides *no* security;

2. Keeping your code private -- I can see your javascript code, can 
you see my php code?

3. Not worrying about what happens when javascript is turned off.

4. Speed -- servers usually process things faster than client side machines.

5. If I want javascript, I can use php to write it -- the reverse isn't true.

6. Resources -- I believe there are more resources for php than for js.

7. Functions -- I believe that there are more functions and thus more 
functionality for php.

8. While 6 & 7 may be arguable, that has been my experience.

9. It has also been my experience that not all javascript is the same 
nor handled the same on all browsers -- however, I may be in error -- 
I just remember reading something to that affect.

10. The only advantage I can see, which is a major one, that that 
javascript can provide more interaction with the user and that 
coupled with ajax (which IS js) becomes a very desirable feature.

But, when all is said and done, it's not a question of php vs 
javascript or css vs html, it's a question of using what language 
"best" fits the problem at hand. And, it's your users and clients who 
make that decision for you.

tedd

-- 
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com



More information about the talk mailing list