i have a php file that contains a form and a php block that contains itself an if condition related to that form. when i try to access it through the browser, it loads the form as expected.But i wanna know what happens to that if statement inside the server, does it ,like, wait until we click some button in the form(like a submit button) and then it reproccess the whole php file again,or it just checks the if condition only and return whatever we put inside that if block.
Asked
Active
Viewed 35 times
0
-
3It is not clear what you are asking so better to show the relevant part of the code. – Harun Yilmaz May 22 '22 at 16:51
-
Loading a `.php` file executes the full file and all PHP inside the script is processed. If you have conditionals only the parts that are true are processed; or the `else` bits will be processed if present. – user3783243 May 22 '22 at 17:03
-
And when you do something which makes a new request to the server (such as submitting a form or clicking a link) then it runs the whole of whatever script is requested – ADyson May 22 '22 at 17:20
-
"it runs the whole of whatever script is requested" that's exactly what I was looking for! – Hicham Jerdaoui May 22 '22 at 18:42
1 Answers
1
You have to understand the difference between client side (browser) and server side (your php script). In your case :
- on server side, the php script send the html script to the web browser it's created with the code it have (if, while, then...). And then, it has finished the work.
- on client side, the html script is read and the browser display it to the user. The user put the input in the form. When validated, it sends the informations to the server side. Then, the php script does it's work with the input received.
Has you can see, there's no direct open link between the client side and the server side. It's important, because the server has limited number of process who can take the requests of the clients. Each request take a process, and after the server does it's stuff, the process is free for another request.
When all process are taken, and a new request come, then the user may have to wait for a response of the server. Sometimes, he will have a timeout or other error, depending on the server configuration.

svgta
- 343
- 1
- 6