|
---------->
HTTP request
|
+--------------+ | +--------------+
| | | | |
| browser | | | web server |
| (JavaScript) | | | (PHP etc.) |
| | | | |
+--------------+ | +--------------+
|
client side | server side
|
<----------
HTML, CSS, JavaScript
|
Execution of PHP takes place on the server, resulting into output of some HTML and JavaScript code. These are meant for the client where the HTML is interpreted and the JavaScript is executed. After the end of response output by PHP, there comes an end to script, and thereafter, no activity takes places on server until the arrival of a new HTTP request.
Below is the example:
<script type="text/javascript">
var foo = 'bar';
<?php
file_put_contents('foo.txt', ' + foo + ');
?>
var baz = <?php echo 42; ?>;
alert(baz);
</script>
Step 1, PHP executes all code between <?php ?> tags. The result is this:
<script type="text/javascript">
var foo = 'bar';
var baz = 42;
alert(baz);
</script>
0 Comment(s)