tags:

views:

64

answers:

5

which one is friendly to develop an webpage application, javascript or php.i want to know which will take less memory and provide more security.

+4  A: 

Javascript and PHP do not serve the same purpose and therefore cannot be compared.

JavaScript is an implementation of the ECMAScript language standard and is typically used to enable programmatic access to computational objects within a host environment.

and

PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document

(via wikipedia)

marcgg
A: 

It depends what you mean by webpage application, you may mean a client side web application that runs completely in the browser, or a server side application which displays it's various views as HTML.

PHP is a server side language for creating server side web applications.

Javascript is typically ECMAScript-262 which can run on either the server or the client and be used to create either server or client side applications.

Neither is more secure, security comes down to how you design and code your applications.

To hazard a guess, I would assume you refer to creating a typical 'dynamic website' like a blog or suchlike, and whilst you can do it with both, I'd recommend using PHP on the serverside primarily because of the huge amount of documentation, tutorials, open source code, libraries, and resources to get you on your way and making things.

Note: you'll probably find you need a little javascript along with your html output as well for design niceties such as AJAX and creating sliders and interactive elements, however this is entirely different to your PHP application on the server.

Hope that helps!

nathan
+1  A: 

In basic terms, Javascript is used primarily to make web pages more interactive, AFTER a web page has been loaded into the web browser. Javascript is a client side programming language. In this case, client means random people surfing the Internet with Internet Explorer, or Firefox, etc... There are other uses for Javascript, but this is the most common use.

PHP on the other hand, is a server side programming language that allows for the creation of dynamic web pages. In this case, dynamic meaning that the content of the pages have context, either in regards to actions and settings of a specific user(guy surfing the web) or relevant to the type of content that a website provides, such as a News website that always has new News articles. Often you will see these two things intermingled to provide each user with a customized and dynamic experience each time they use a website. These pages, while dynamic, aren't dynamic in the same way that javascript can be, because the client(web browser) has to send a request to the server every time it needs more information and that request leads to the web browser needing to load a new web page.

The dynamic part of Javascript comes from it being able to respond to the user's actions without requesting more information from the server or by requesting a very small amount of informaiton from the server and not causing the entire web page to reload. While this a good thing, it is limited. Because Javascript is a client side programming language, it is not secure, meaning that if your server needs to save or use any data touched by Javascript, it should be sanitized(inspected and possibly modified) before it can be trusted. This is true of information that is submitted through regular HTML forms as well. Javascript is also limited by data size factors since a large and complex website, if created using just Javacript, would require a ton of information to be loaded all at once and that doesn't work well for websites because people expect them to load quickly. Also, if you intend to use a database, client side Javascript has no options for you. PHP on the other hand can work with databases pretty easily.

All that said, these programming languages are very complimentary to each other and are OFTEN used together to provide an interactive and dynamic user experience on websites. So it is not a question of which one to use, but instead, how to make them work together in the best possible way. Answering THAT question in new and better ways is something that many programmers get paid to do everyday :)

Please keep in mind that I am just briefly giving an overview of the main topic and there are MANY sub topics within that main one. A good starting point to learning about these technologies would be HTTP. http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

tsgrasser
A: 

See the Best Practices of each one, you will find what you want:

Javascriot Best Practices

PHP Best Practices

Amirouche Douda
If there is a comparison of ease of memory usage and implementation of security behind those links, I can't find it.
David Dorward
I've gave you a general example of Best Practices for each one, my answer aim to give you the term "Best Practices", the latter can be used in security, in progrmmation and so, according to what you're looking for.
Amirouche Douda
That doesn't answer the question though.
David Dorward
A: 

I would venture to say both in conjunction with one another. I worked at a company recently that used server-side code for heavy duty stuff and client-side Javascript for validation, some session support, cookies, browser compatibility testing, etc. Javascript is nice as it renders on the client's machine (the browser bears the brunt of the work). PHP, however, will likely be required when doing heavy lifting, working with an MVC models, database access, etc. Also keep in mind that your users will have access to Javascript code used, but not to PHP as that's server-side.

MattB