First and foremost, forgive me for my complete lack of knowledge of web development. I have just recently found interest in this topic but I need some answers to clear things up. And second, I have tried searching for this before but couldn't find the answer I was looking for.
Again, sorry, I have absolutely 0 experience with web development and I hope the answer to this question will clear up some things for newcomers like me.
Your 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 completed the form and submitted it. JS then comes 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
So it can compactly 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.
.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.
Clients need to use JS to send information to the server for its response.
Client needs to send information to a address e.g. http://example.com/response.php to get a response. So yes, it disregards where the PHP is, because if it is one single .php file, the client still sends information to the same address the webpage was downloaded to get response.
Indeed. Clients download a webpage, not using the same in the server, changes can be made before information sending, so hackers can hack people's passwords. Clients don't get to read the PHP, so they send queries to the server, while the server only reads anything PHP, because the .php webpage is unaltered on the server, that's why people use PHP to prevent hacking. After the PHP server has responded, usually, they will insert information in the webpage browsing and trigger JS code to execute to change the webpage's HTML and CSS.