Knowledgebase

What is the difference between PHP and JavaScript?

Posted by 3DProf4online, 08-21-2008, 08:38 AM
Hello guys could you please explain an newbie how these technologies are different from each other?

Posted by folsom, 08-21-2008, 08:57 AM
The difference is that PHP runs on the server and javascript runs in the user's web browser. A server can also run javascript, but mostly you will not have to think about that.

Posted by kemuel, 08-21-2008, 09:36 AM
Adding to what folsom already said: as js is client-side it is mostly used for graphical things or changes after the page is loaded, such as a ticking clock (no database interaction and such). Users are able to view your JavaScript code when they click view source, whereas PHP will be interpreted before it leaves the server and thus only the output will be available to the user. Javascript can also be combined with XML, this is called AJAX (Asynchronous JavaScript and XML) which can actually request new data after the page has loaded without having to refresh and is used for instance to renew data provided by a php script without having to call the script again by, as said before, refreshing it.

Posted by 3DProf4online, 08-22-2008, 07:17 AM
Also, I would like to ask what things can be done using JS and can't be done using PHP scripts?

Posted by kemuel, 08-22-2008, 07:39 AM
Any changes done without refreshing the page. For instance moving an image around or the seconds updating on a click or changing the content of a table when you hover something, etc... It is used mostly for the graphical side of things, or for adding better functionality to your html. A good example of the latter would be: checking if what a user is typing in a text box fits a particular format (before submitting).

Posted by Xeentech, 08-22-2008, 08:54 AM
Following on from the validation example.. after the user has finished filling in the form data and javascript has test it for validity PHP would typically be used on the server side to again confirm the data entered is in a valid format. This is because the PHP on the remote server can not be edited by the user and can be trusted to enter data directly into the database (after some scrutiny).

Posted by awatson, 08-22-2008, 01:19 PM
Another difference (which Xeentech sort of hinted at) is that javascript can be totally bypassed by the user, but there's no way they can "turn off" php (since it runs on the server, not in the browser.)

Posted by etogre, 08-22-2008, 11:28 PM
You are trying to compare apples and oranges.

Posted by JustinSmall, 08-28-2008, 07:42 AM
I was thinking the same thing... I would have figured he'd ask a question like: "What is the difference between ASP and PHP?" or even, "What is the difference between Javascript and Ajax?" Anyways, Javascript is more of a client side programming… whereas, php is a server side programming. When asking the difference in coding, you must ask the question for the difference in all of them… PHP MySQL Java JavaScript CSS ASP ASP.net Perl Python CGI Ruby on Rails Ajax C# VB.NET and of course XHTMl/HTML these are some of the more common and diverse programming languages.

Posted by 3DProf4online, 08-28-2008, 08:42 AM
Could you please just explain what things can't be performed without Java Script?

Posted by livechatr, 08-28-2008, 08:49 AM
JavaScript allows you to add some kind of interactivity to your web page without reloading/refreshing it. E.g. you can check if an email address entered by a visitor on your registration page is well-formed (e.g. looks like nickname, followed by @, and followed by domain.tld; this is oversimplified, though) WITHOUT submitting this page to the server. You can immediately popup a dialog saying "Sorry, your email address is not well-formed". This is just an example. I would say, that you cannot achieve that kind of interactivity without page refreshes, if you have JavaScript turned OFF. This just my humble opinion, and how I see it. Last edited by livechatr; 08-28-2008 at 08:50 AM. Reason: bad punctuation =)

Posted by 3DProf4online, 08-28-2008, 10:07 AM
So, JavaScript will allow a website to work quicker, right?

Posted by livechatr, 08-29-2008, 04:26 AM
Well, this might save your visitors some page refreshes, which should definitely speed up the overall interaction process.

Posted by SolidTools, 08-31-2008, 10:13 PM
Simply put, JavaScript is client side code, runs with web browsers, and PHP is a server side language, runs on the server side. <> Last edited by sirius; 08-31-2008 at 10:48 PM.

Posted by zinga, 09-01-2008, 03:10 AM
Stuff like storing info like a forum system. Javascript/AJAX can be used to send info to the server, but ultimately, there needs to be something that handles the request. Think of it this way: when you visit a website like a forum such as this one, there are two (primary) parties involved - you/your computer and the server hosting this website. Your browser needs to send something to the server and the server needs to know what to send to the browser. In essence, browsers known how to send requests to the server (it's a standard procedure), however, the server, for dynamic sites such as a forum, usually needs something to tell it what data (ie posts) to send to the client (you). This is handled, usually, via a server side script, such as PHP. Javascript is quite a different thing. In essence, it's not necessary on many websites. Javascript runs on your computer, and as such, is much more restricted in terms of system access as opposed to PHP (ie, theortically, a website can't use Javascript to write files to your harddrive). Javascript mainly allows webpages to be a little more flexible than just a dump of text and images... (ie interactive menus etc)

Posted by JustinSmall, 09-01-2008, 07:31 PM
There are angles at which Javascript can make a website a lot quicker and a lot smoother. Such as interaction, whereas, you can refresh a particular part of a page - such as a div - instead of refreshing the whole page, which is quicker However, on older systems, it can run very slow and boggy. I have PC's of all calibers, and the Javascript runs differently on each one of them. I would still promote Javascript to anyone and everyone, not in all instances, because when used properly it can be very effective.



Was this answer helpful?

Add to Favourites Add to Favourites

Print this Article Print this Article

Also Read
Failover setup (Views: 595)


Language:

Client Login

Email

Password

Remember Me

Search