I often hear of the term server-side and client-side programming in regards to web development. They say that server-side and client-side are in a way decoupled from each other. From my understanding, server-side programming makes use of PHP, Rails, Node, ASP.NET, etc., as the technologies and client-side programming makes use of HTML, CSS, Javascript, etc.
Here is where I am fundamentally confused.. From what I know, a PHP file can include HTML, CSS, and Javascript... My question is:
If server-side and client-side programming are indeed separate, why does PHP include HTML, CSS and Javascript? If all of these are done in PHP, the server, where does the client e in? In a typical website run on a PHP server, will there be standalone HTML, CSS, and Javascript files that are not PHP files? Will the client-side developer have have edit the HTML, CSS, and Javascript parts of the PHP file, while the server-side developer works on the PHP part of the file?
I often hear of the term server-side and client-side programming in regards to web development. They say that server-side and client-side are in a way decoupled from each other. From my understanding, server-side programming makes use of PHP, Rails, Node, ASP.NET, etc., as the technologies and client-side programming makes use of HTML, CSS, Javascript, etc.
Here is where I am fundamentally confused.. From what I know, a PHP file can include HTML, CSS, and Javascript... My question is:
If server-side and client-side programming are indeed separate, why does PHP include HTML, CSS and Javascript? If all of these are done in PHP, the server, where does the client e in? In a typical website run on a PHP server, will there be standalone HTML, CSS, and Javascript files that are not PHP files? Will the client-side developer have have edit the HTML, CSS, and Javascript parts of the PHP file, while the server-side developer works on the PHP part of the file?
Share Improve this question edited Mar 16, 2017 at 17:12 MD XF 8,1299 gold badges44 silver badges74 bronze badges asked Apr 23, 2014 at 13:46 brandontobrandonto 1252 silver badges10 bronze badges 2- They're not as decoupled as you think. In many cases server side code is used to create or modify client code before it's sent to the client. In your example the php code in the php file is used to add data to the html before it is sent to the client. – Shaded Commented Apr 23, 2014 at 13:49
- Browsers don't run PHP, JAVA, Ruby, ASP.NET. These languages build, merge, mix things together generating some text that browsers DO run. – enapupe Commented Apr 23, 2014 at 13:51
5 Answers
Reset to default 6Your question sure is a good one many people asked sometime in their lives(web developers).
PHP indeed is a server side script, but the .php
extension acts like a normal .html
file most of the time.
PHP needs to be a partner with JS and HTML to work.
E.g. A login form. First, the client has pleted the form and submitted it. JS then es in power, using ajax to send your login information to the server(It could be the same document xxx.php, but the server only cares about the php script part).
Then, it sends back a result from the server and may insert a snippet of JS into your login form, where JS empowers and redirect the user from their HTML interface to a new website.
As you can see from the above example, clients and server handles a webpage differently disregarding their file extension. Clients cannot download the PHP source code and the PHP server doesn't care about other than php code themselves.
A single web file is like a port, where clients send information to a php page and the server returns a snippet.
Clients and servers may use one single .php page or can refer to different pages, but the server side webpage is always unaltered
If server-side and client-side programming are indeed separate, why does PHP include HTML, CSS and Javascript?
So it can pactly pack small things inside one web page. Clients view the interface, server executes the PHP code. However, it is not necessary to pack everything into one webpage.
Also, the .php
extension can be viewed by clients, so that they know they will interact with the server sometime on that page. Also, .php
does not necessary need to include PHP code.
If all of these are done in PHP, the server, where does the client e in?
Clients need to use JS to send information to the server for its response.
On a typical webpage running on a PHP, will there be standalone HTML, CSS, and JavaScript files that are not PHP files?
Yes, files that need not to be parsed by the PHP engine can be named and stored as standalone HTML, CSS and JavaScript file.
Will the client-side developer have have edit the HTML, CSS, and Javascript parts of the PHP file, while the server-side developer works on the PHP part of the file?
I will rephrase your question to be "So the client-side browser can change the DOM, while the server works on the PHP part?". There is no "client sided developer. There is just client sided visitors"
Partially right. Clients download a webpage, not using the same file on the server, the webpage can be altered before sending to the clients. Clients don't get to read the PHP source code, the server is done running the PHP code before sending a webpage to the clients, so the two do not run together. When clients send queries to the server, the server executes nothing but PHP. The .php document is unaltered on the server. After the PHP server has responded, usually, they will send back information to the browser viewing that particular webpage and trigger JS code and change the webpage's DOM, which means the look of the webpage is modified. You can interpret it as "HTML, CSS and JS" being altered.
If all of these are done in PHP, the server, where does the client e in?
The WWW works on a server-client basis.
Web browsers ask web servers for resources. Web servers send those resources to the browser. The browser then interprets them.
When you use server side programming, you just generate those resources programatically instead of reading them from files.
So:
- the PHP will run on the server and generate some output
- the output it sent to the browser
- the browser interprets the output
So the output has to be in a form that the browser understands.
In a typical website run on a PHP server, will there be standalone HTML, CSS, and Javascript files that are not PHP files?
Generally speaking, the CSS and JS will be in static files. The HTML contains the data which is likely to be dynamic (and then generated from PHP) so will probably e from PHP files (although they might use separate template files to get the HTML structure).
Will the client-side developer have have edit the HTML, CSS, and Javascript parts of the PHP file, while the server-side developer works on the PHP part of the file?
There are lots of different ways of working. If you get your server side logic sufficiently separated from from your client side code, then that is a viable way of working.
PHP needs to be executed on the server. The PHP usually determines which CSS/JS/HTML to export to the client. Therefore it is in the PHP file.
HTML, CSS and JS actually is executed on client side. The reason it is in your PHP file, is we need some way of delivering the code to the client. It doesn't just magically appear.
CSS and JS doesn't even have to be in the PHP file. You can use HTML inclusions to let the browser fetch it
eg.
<script src="/loc/of/js/file.js"></script> (JS)
<link href="/loc/of/css/file.css" rel="stylesheet"> (CSS)
Whene you use PHP page, means you want to execute some code in your server at the same time you can include some JS code , or CSS styles, but the server will not execute it. All the PHP code will be exucuted by the Server. CSS and JS code will be interprets by your browser because they're front-end code.
All PHP does is that it creates html pages which contain css and javascript code as well and sends it to client. Now how php creates a page differs in application. I hope it helps.