What is the difference between client-side and server-side programming?












438















I have this code:



<script type="text/javascript">
var foo = 'bar';
<?php
file_put_contents('foo.txt', ' + foo + ');
?>

var baz = <?php echo 42; ?>;
alert(baz);
</script>


Why does this not write "bar" into my text file, but alerts "42"?





NB: Earlier revisions of this question were explicitly about PHP on the server and JavaScript on the client. The essential nature of the problem and solutions is the same for any pair of languages when one is running on the client and the other on the server. Please take this in to account when you see answers talking about specific languages.










share|improve this question

























  • The file_put_contents ought to be edited to have some possibility of actually referencing the foo variable. As-is, it's just writing a static string to the file and is really not demonstrating the server-side vs. client-side execution issue.

    – Andrew Medico
    May 12 '14 at 19:02











  • @Andrew That's the point, there is no possibility. It's a sample code to introduce the problem. If you have a better suggestion, please feel free to edit it.

    – deceze
    May 12 '14 at 19:23
















438















I have this code:



<script type="text/javascript">
var foo = 'bar';
<?php
file_put_contents('foo.txt', ' + foo + ');
?>

var baz = <?php echo 42; ?>;
alert(baz);
</script>


Why does this not write "bar" into my text file, but alerts "42"?





NB: Earlier revisions of this question were explicitly about PHP on the server and JavaScript on the client. The essential nature of the problem and solutions is the same for any pair of languages when one is running on the client and the other on the server. Please take this in to account when you see answers talking about specific languages.










share|improve this question

























  • The file_put_contents ought to be edited to have some possibility of actually referencing the foo variable. As-is, it's just writing a static string to the file and is really not demonstrating the server-side vs. client-side execution issue.

    – Andrew Medico
    May 12 '14 at 19:02











  • @Andrew That's the point, there is no possibility. It's a sample code to introduce the problem. If you have a better suggestion, please feel free to edit it.

    – deceze
    May 12 '14 at 19:23














438












438








438


91






I have this code:



<script type="text/javascript">
var foo = 'bar';
<?php
file_put_contents('foo.txt', ' + foo + ');
?>

var baz = <?php echo 42; ?>;
alert(baz);
</script>


Why does this not write "bar" into my text file, but alerts "42"?





NB: Earlier revisions of this question were explicitly about PHP on the server and JavaScript on the client. The essential nature of the problem and solutions is the same for any pair of languages when one is running on the client and the other on the server. Please take this in to account when you see answers talking about specific languages.










share|improve this question
















I have this code:



<script type="text/javascript">
var foo = 'bar';
<?php
file_put_contents('foo.txt', ' + foo + ');
?>

var baz = <?php echo 42; ?>;
alert(baz);
</script>


Why does this not write "bar" into my text file, but alerts "42"?





NB: Earlier revisions of this question were explicitly about PHP on the server and JavaScript on the client. The essential nature of the problem and solutions is the same for any pair of languages when one is running on the client and the other on the server. Please take this in to account when you see answers talking about specific languages.







javascript php client-side server-side






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 15 '17 at 12:17









Quentin

655k728901054




655k728901054










asked Dec 12 '12 at 13:03









decezedeceze

399k63543701




399k63543701













  • The file_put_contents ought to be edited to have some possibility of actually referencing the foo variable. As-is, it's just writing a static string to the file and is really not demonstrating the server-side vs. client-side execution issue.

    – Andrew Medico
    May 12 '14 at 19:02











  • @Andrew That's the point, there is no possibility. It's a sample code to introduce the problem. If you have a better suggestion, please feel free to edit it.

    – deceze
    May 12 '14 at 19:23



















  • The file_put_contents ought to be edited to have some possibility of actually referencing the foo variable. As-is, it's just writing a static string to the file and is really not demonstrating the server-side vs. client-side execution issue.

    – Andrew Medico
    May 12 '14 at 19:02











  • @Andrew That's the point, there is no possibility. It's a sample code to introduce the problem. If you have a better suggestion, please feel free to edit it.

    – deceze
    May 12 '14 at 19:23

















The file_put_contents ought to be edited to have some possibility of actually referencing the foo variable. As-is, it's just writing a static string to the file and is really not demonstrating the server-side vs. client-side execution issue.

– Andrew Medico
May 12 '14 at 19:02





The file_put_contents ought to be edited to have some possibility of actually referencing the foo variable. As-is, it's just writing a static string to the file and is really not demonstrating the server-side vs. client-side execution issue.

– Andrew Medico
May 12 '14 at 19:02













@Andrew That's the point, there is no possibility. It's a sample code to introduce the problem. If you have a better suggestion, please feel free to edit it.

– deceze
May 12 '14 at 19:23





@Andrew That's the point, there is no possibility. It's a sample code to introduce the problem. If you have a better suggestion, please feel free to edit it.

– deceze
May 12 '14 at 19:23












5 Answers
5






active

oldest

votes


















411














Your code is split into two entirely separate parts, the server side and the client side.



                    |
---------->
HTTP request
|
+--------------+ | +--------------+
| | | | |
| browser | | | web server |
| (JavaScript) | | | (PHP etc.) |
| | | | |
+--------------+ | +--------------+
|
client side | server side
|
<----------
HTML, CSS, JavaScript
|


The two sides communicate via HTTP requests and responses. PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed. Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.



The example code executes like this:



<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>


The file_put_contents call did not result in anything, it just wrote " + foo + " into a file. The <?php echo 42; ?> call resulted in the output "42", which is now in the spot where that code used to be.



This resulting HTML/JavaScript code is now sent to the client, where it gets evaluated. The alert call works, while the foo variable is not used anywhere.



All PHP code is executed on the server before the client even starts executing any of the JavaScript. There's no PHP code left in the response that JavaScript could interact with.



To call some PHP code, the client will have to send a new HTTP request to the server. This can happen using one of three possible methods:




  1. A link, which causes the browser to load a new page.

  2. A form submission, which submits data to the server and loads a new page.

  3. An AJAX request, which is a Javascript technique to make a regular HTTP request to the server (like 1. and 2. will), but without leaving the current page.


Here's a question outlining these method in greater detail



You can also use JavaScript to make the browser open a new page using window.location or submit a form, emulating possibilities 1. and 2.






share|improve this answer





















  • 1





    You can also open second page using window.open or load a page using an iframe.

    – jcubic
    Apr 25 '16 at 7:51













  • It might be worth adding WebSockets to the list of communication methods.

    – Quentin
    Dec 19 '16 at 8:45











  • What if let's say drop down values get updated via jquery. When user does step 2. A form submission, which submits data to the server and loads a new page, via "Submit" button would the jquery updated values be able to be passed to a controller in php? Or would they not be visible to php since it was added to the dom via jquery? @deceze

    – FabricioG
    Oct 2 '18 at 22:33











  • @Fabricio An HTTP request will be created from the <form> data and sent to the server. You can manipulate forms using Javascript to have them contain different data. Yes, that data will be part of the resulting HTTP request if it's properly part of the form when it is being submitted; it doesn't matter whether it was in the original HTML or added afterwards via Javascript.

    – deceze
    Oct 3 '18 at 7:30



















148














To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.



Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user




Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svgimage attr




So you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.



While at the other hand Client Side Language (like JavaScript) resides on browser and runs at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.



JavaScript is visible to the user and can be easily modified so for security stuff we must not rely on JavaScript.



So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said *Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.*




Graphical representation



Image source




So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.




  1. You can do by reloading page and send HTTP request

  2. you can make AJAX call with JavaScript and this does not require reloading page


Good Read:




  1. Wikipedia : Server-side scripting

  2. Wikipedia : Client-side scripting

  3. Madara Uchiha : Difference between client side and server side programming






share|improve this answer

































    24














    Your Javascript will execute on the client, not on the server. This means that foo is not evaluated on the server side and therefore its value can't be written to a file on the server.



    The best way to think about this process is as if you're generating a text file dynamically. The text you're generating only becomes executable code once the browser interprets it. Only what you place between <?php tags is evaluated on the server.



    By the way, making a habit of embedding random pieces of PHP logic in HTML or Javascript can lead to seriously convoluted code. I speak from painful experience.






    share|improve this answer



















    • 3





      Your answer here is noteworthy as it makes mention to the/a interpeter. However, javascript can be compiled and run in a server environment, and it can be interpeted by a server as well.

      – Brett Caswell
      Mar 10 '15 at 17:10



















    3














    In web application every task execute in a manner of request and response.



    Client side programming is with html code with Java script and its frameworks, libraries executes in the internet explorer, Mozilla, chrome browsers.
    In the java scenario
    server side programming servlets executes in the Tomcat, web-logic , j boss, WebSphere severs






    share|improve this answer































      0














      I will try to explain it in simple way.



      Client Side is what user see/ code which is visible on browser.



      Client Side Programming includes HTML(HTML, HTML5, DHTML), CSS(CSS, CSS3) and JavaScript(JavaScript, ES5, ES6, ES7, TypeScript, JQuery, ReactJs, AngularJs, BackboneJs or any other JavaScript Front-end framework).



      Client Side programming focus on "how page will look like" and its behavior over browsers.




      1. HTML is what we see.

      2. CSS decides its designing(Colours, Floating Images, Padding, etc).

      3. JavaScript monitor page information. All the API calls and maintaining data over DOM is done by JavaScript.


      Server Side Programming includes code which provide data to Client-Side. User is never able to see server-side.



      Server Side Programming involves Programming Language(Java, PHP, .Net, C#, C, C++, NodeJS etc), Database(SQL, Oracle, MySql, PostgreySql, No-Sql, MongoDB, etc), Third Party API(Rest, Soap), Business Logic.



      Server Side Programming focus on "how to make data available for Client-Side".




      1. Server-Side Language is responsible for communicating between different source of data like database, third-party API, file system, blockchain etc,. These languages maintain certain API for client-side to interact with.

      2. Database is responsible for storing information.

      3. Business Logic defines "how to use data and what to do with data".


      Client-Side request data or request to store data, from Server-side via API provided by Server-Side. This request and response of data is done by following HTTP/FTP protocol like REST API, SOAP API.






      share|improve this answer





















      • 1





        While this tries to answer the question posed in the title, it completely ignores the detail of the question body so doesn't address the problem at all.

        – Quentin
        Oct 22 '18 at 11:20












      protected by Alma Do Aug 11 '14 at 9:41



      Thank you for your interest in this question.
      Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



      Would you like to answer one of these unanswered questions instead?














      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      411














      Your code is split into two entirely separate parts, the server side and the client side.



                          |
      ---------->
      HTTP request
      |
      +--------------+ | +--------------+
      | | | | |
      | browser | | | web server |
      | (JavaScript) | | | (PHP etc.) |
      | | | | |
      +--------------+ | +--------------+
      |
      client side | server side
      |
      <----------
      HTML, CSS, JavaScript
      |


      The two sides communicate via HTTP requests and responses. PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed. Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.



      The example code executes like this:



      <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>


      The file_put_contents call did not result in anything, it just wrote " + foo + " into a file. The <?php echo 42; ?> call resulted in the output "42", which is now in the spot where that code used to be.



      This resulting HTML/JavaScript code is now sent to the client, where it gets evaluated. The alert call works, while the foo variable is not used anywhere.



      All PHP code is executed on the server before the client even starts executing any of the JavaScript. There's no PHP code left in the response that JavaScript could interact with.



      To call some PHP code, the client will have to send a new HTTP request to the server. This can happen using one of three possible methods:




      1. A link, which causes the browser to load a new page.

      2. A form submission, which submits data to the server and loads a new page.

      3. An AJAX request, which is a Javascript technique to make a regular HTTP request to the server (like 1. and 2. will), but without leaving the current page.


      Here's a question outlining these method in greater detail



      You can also use JavaScript to make the browser open a new page using window.location or submit a form, emulating possibilities 1. and 2.






      share|improve this answer





















      • 1





        You can also open second page using window.open or load a page using an iframe.

        – jcubic
        Apr 25 '16 at 7:51













      • It might be worth adding WebSockets to the list of communication methods.

        – Quentin
        Dec 19 '16 at 8:45











      • What if let's say drop down values get updated via jquery. When user does step 2. A form submission, which submits data to the server and loads a new page, via "Submit" button would the jquery updated values be able to be passed to a controller in php? Or would they not be visible to php since it was added to the dom via jquery? @deceze

        – FabricioG
        Oct 2 '18 at 22:33











      • @Fabricio An HTTP request will be created from the <form> data and sent to the server. You can manipulate forms using Javascript to have them contain different data. Yes, that data will be part of the resulting HTTP request if it's properly part of the form when it is being submitted; it doesn't matter whether it was in the original HTML or added afterwards via Javascript.

        – deceze
        Oct 3 '18 at 7:30
















      411














      Your code is split into two entirely separate parts, the server side and the client side.



                          |
      ---------->
      HTTP request
      |
      +--------------+ | +--------------+
      | | | | |
      | browser | | | web server |
      | (JavaScript) | | | (PHP etc.) |
      | | | | |
      +--------------+ | +--------------+
      |
      client side | server side
      |
      <----------
      HTML, CSS, JavaScript
      |


      The two sides communicate via HTTP requests and responses. PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed. Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.



      The example code executes like this:



      <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>


      The file_put_contents call did not result in anything, it just wrote " + foo + " into a file. The <?php echo 42; ?> call resulted in the output "42", which is now in the spot where that code used to be.



      This resulting HTML/JavaScript code is now sent to the client, where it gets evaluated. The alert call works, while the foo variable is not used anywhere.



      All PHP code is executed on the server before the client even starts executing any of the JavaScript. There's no PHP code left in the response that JavaScript could interact with.



      To call some PHP code, the client will have to send a new HTTP request to the server. This can happen using one of three possible methods:




      1. A link, which causes the browser to load a new page.

      2. A form submission, which submits data to the server and loads a new page.

      3. An AJAX request, which is a Javascript technique to make a regular HTTP request to the server (like 1. and 2. will), but without leaving the current page.


      Here's a question outlining these method in greater detail



      You can also use JavaScript to make the browser open a new page using window.location or submit a form, emulating possibilities 1. and 2.






      share|improve this answer





















      • 1





        You can also open second page using window.open or load a page using an iframe.

        – jcubic
        Apr 25 '16 at 7:51













      • It might be worth adding WebSockets to the list of communication methods.

        – Quentin
        Dec 19 '16 at 8:45











      • What if let's say drop down values get updated via jquery. When user does step 2. A form submission, which submits data to the server and loads a new page, via "Submit" button would the jquery updated values be able to be passed to a controller in php? Or would they not be visible to php since it was added to the dom via jquery? @deceze

        – FabricioG
        Oct 2 '18 at 22:33











      • @Fabricio An HTTP request will be created from the <form> data and sent to the server. You can manipulate forms using Javascript to have them contain different data. Yes, that data will be part of the resulting HTTP request if it's properly part of the form when it is being submitted; it doesn't matter whether it was in the original HTML or added afterwards via Javascript.

        – deceze
        Oct 3 '18 at 7:30














      411












      411








      411







      Your code is split into two entirely separate parts, the server side and the client side.



                          |
      ---------->
      HTTP request
      |
      +--------------+ | +--------------+
      | | | | |
      | browser | | | web server |
      | (JavaScript) | | | (PHP etc.) |
      | | | | |
      +--------------+ | +--------------+
      |
      client side | server side
      |
      <----------
      HTML, CSS, JavaScript
      |


      The two sides communicate via HTTP requests and responses. PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed. Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.



      The example code executes like this:



      <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>


      The file_put_contents call did not result in anything, it just wrote " + foo + " into a file. The <?php echo 42; ?> call resulted in the output "42", which is now in the spot where that code used to be.



      This resulting HTML/JavaScript code is now sent to the client, where it gets evaluated. The alert call works, while the foo variable is not used anywhere.



      All PHP code is executed on the server before the client even starts executing any of the JavaScript. There's no PHP code left in the response that JavaScript could interact with.



      To call some PHP code, the client will have to send a new HTTP request to the server. This can happen using one of three possible methods:




      1. A link, which causes the browser to load a new page.

      2. A form submission, which submits data to the server and loads a new page.

      3. An AJAX request, which is a Javascript technique to make a regular HTTP request to the server (like 1. and 2. will), but without leaving the current page.


      Here's a question outlining these method in greater detail



      You can also use JavaScript to make the browser open a new page using window.location or submit a form, emulating possibilities 1. and 2.






      share|improve this answer















      Your code is split into two entirely separate parts, the server side and the client side.



                          |
      ---------->
      HTTP request
      |
      +--------------+ | +--------------+
      | | | | |
      | browser | | | web server |
      | (JavaScript) | | | (PHP etc.) |
      | | | | |
      +--------------+ | +--------------+
      |
      client side | server side
      |
      <----------
      HTML, CSS, JavaScript
      |


      The two sides communicate via HTTP requests and responses. PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed. Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.



      The example code executes like this:



      <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>


      The file_put_contents call did not result in anything, it just wrote " + foo + " into a file. The <?php echo 42; ?> call resulted in the output "42", which is now in the spot where that code used to be.



      This resulting HTML/JavaScript code is now sent to the client, where it gets evaluated. The alert call works, while the foo variable is not used anywhere.



      All PHP code is executed on the server before the client even starts executing any of the JavaScript. There's no PHP code left in the response that JavaScript could interact with.



      To call some PHP code, the client will have to send a new HTTP request to the server. This can happen using one of three possible methods:




      1. A link, which causes the browser to load a new page.

      2. A form submission, which submits data to the server and loads a new page.

      3. An AJAX request, which is a Javascript technique to make a regular HTTP request to the server (like 1. and 2. will), but without leaving the current page.


      Here's a question outlining these method in greater detail



      You can also use JavaScript to make the browser open a new page using window.location or submit a form, emulating possibilities 1. and 2.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 23 '17 at 12:02









      Community

      11




      11










      answered Dec 12 '12 at 13:03









      decezedeceze

      399k63543701




      399k63543701








      • 1





        You can also open second page using window.open or load a page using an iframe.

        – jcubic
        Apr 25 '16 at 7:51













      • It might be worth adding WebSockets to the list of communication methods.

        – Quentin
        Dec 19 '16 at 8:45











      • What if let's say drop down values get updated via jquery. When user does step 2. A form submission, which submits data to the server and loads a new page, via "Submit" button would the jquery updated values be able to be passed to a controller in php? Or would they not be visible to php since it was added to the dom via jquery? @deceze

        – FabricioG
        Oct 2 '18 at 22:33











      • @Fabricio An HTTP request will be created from the <form> data and sent to the server. You can manipulate forms using Javascript to have them contain different data. Yes, that data will be part of the resulting HTTP request if it's properly part of the form when it is being submitted; it doesn't matter whether it was in the original HTML or added afterwards via Javascript.

        – deceze
        Oct 3 '18 at 7:30














      • 1





        You can also open second page using window.open or load a page using an iframe.

        – jcubic
        Apr 25 '16 at 7:51













      • It might be worth adding WebSockets to the list of communication methods.

        – Quentin
        Dec 19 '16 at 8:45











      • What if let's say drop down values get updated via jquery. When user does step 2. A form submission, which submits data to the server and loads a new page, via "Submit" button would the jquery updated values be able to be passed to a controller in php? Or would they not be visible to php since it was added to the dom via jquery? @deceze

        – FabricioG
        Oct 2 '18 at 22:33











      • @Fabricio An HTTP request will be created from the <form> data and sent to the server. You can manipulate forms using Javascript to have them contain different data. Yes, that data will be part of the resulting HTTP request if it's properly part of the form when it is being submitted; it doesn't matter whether it was in the original HTML or added afterwards via Javascript.

        – deceze
        Oct 3 '18 at 7:30








      1




      1





      You can also open second page using window.open or load a page using an iframe.

      – jcubic
      Apr 25 '16 at 7:51







      You can also open second page using window.open or load a page using an iframe.

      – jcubic
      Apr 25 '16 at 7:51















      It might be worth adding WebSockets to the list of communication methods.

      – Quentin
      Dec 19 '16 at 8:45





      It might be worth adding WebSockets to the list of communication methods.

      – Quentin
      Dec 19 '16 at 8:45













      What if let's say drop down values get updated via jquery. When user does step 2. A form submission, which submits data to the server and loads a new page, via "Submit" button would the jquery updated values be able to be passed to a controller in php? Or would they not be visible to php since it was added to the dom via jquery? @deceze

      – FabricioG
      Oct 2 '18 at 22:33





      What if let's say drop down values get updated via jquery. When user does step 2. A form submission, which submits data to the server and loads a new page, via "Submit" button would the jquery updated values be able to be passed to a controller in php? Or would they not be visible to php since it was added to the dom via jquery? @deceze

      – FabricioG
      Oct 2 '18 at 22:33













      @Fabricio An HTTP request will be created from the <form> data and sent to the server. You can manipulate forms using Javascript to have them contain different data. Yes, that data will be part of the resulting HTTP request if it's properly part of the form when it is being submitted; it doesn't matter whether it was in the original HTML or added afterwards via Javascript.

      – deceze
      Oct 3 '18 at 7:30





      @Fabricio An HTTP request will be created from the <form> data and sent to the server. You can manipulate forms using Javascript to have them contain different data. Yes, that data will be part of the resulting HTTP request if it's properly part of the form when it is being submitted; it doesn't matter whether it was in the original HTML or added afterwards via Javascript.

      – deceze
      Oct 3 '18 at 7:30













      148














      To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.



      Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user




      Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svgimage attr




      So you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.



      While at the other hand Client Side Language (like JavaScript) resides on browser and runs at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.



      JavaScript is visible to the user and can be easily modified so for security stuff we must not rely on JavaScript.



      So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said *Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.*




      Graphical representation



      Image source




      So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.




      1. You can do by reloading page and send HTTP request

      2. you can make AJAX call with JavaScript and this does not require reloading page


      Good Read:




      1. Wikipedia : Server-side scripting

      2. Wikipedia : Client-side scripting

      3. Madara Uchiha : Difference between client side and server side programming






      share|improve this answer






























        148














        To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.



        Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user




        Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svgimage attr




        So you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.



        While at the other hand Client Side Language (like JavaScript) resides on browser and runs at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.



        JavaScript is visible to the user and can be easily modified so for security stuff we must not rely on JavaScript.



        So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said *Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.*




        Graphical representation



        Image source




        So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.




        1. You can do by reloading page and send HTTP request

        2. you can make AJAX call with JavaScript and this does not require reloading page


        Good Read:




        1. Wikipedia : Server-side scripting

        2. Wikipedia : Client-side scripting

        3. Madara Uchiha : Difference between client side and server side programming






        share|improve this answer




























          148












          148








          148







          To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.



          Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user




          Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svgimage attr




          So you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.



          While at the other hand Client Side Language (like JavaScript) resides on browser and runs at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.



          JavaScript is visible to the user and can be easily modified so for security stuff we must not rely on JavaScript.



          So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said *Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.*




          Graphical representation



          Image source




          So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.




          1. You can do by reloading page and send HTTP request

          2. you can make AJAX call with JavaScript and this does not require reloading page


          Good Read:




          1. Wikipedia : Server-side scripting

          2. Wikipedia : Client-side scripting

          3. Madara Uchiha : Difference between client side and server side programming






          share|improve this answer















          To determine why PHP code doesn't work in JavaScript code we need to understand what is client side and server side language and how they work.



          Server-side languages (PHP etc.): They retrieve records from databases, maintain state over the stateless HTTP connection, and do a lot of things that require security. They reside on the server, these programs never have their source code exposed to the user




          Image from wikipedia_http://en.wikipedia.org/wiki/File:Scheme_dynamic_page_en.svgimage attr




          So you can easily see that server side language handle HTTP request and process it and as @deceze said PHP is executed on the server and outputs some HTML and maybe JavaScript code which is sent as response to the client where the HTML is interpreted and the JavaScript is executed.



          While at the other hand Client Side Language (like JavaScript) resides on browser and runs at the browser, Client-side scripting generally refers to the class of computer programs on the web that are executed client-side, by the user's web browser, instead of server-side.



          JavaScript is visible to the user and can be easily modified so for security stuff we must not rely on JavaScript.



          So when you make a HTTP request on server than The server first reads the PHP file carefully to see if there are any tasks that need to be executed and send response to client side and again as @deceze said *Once PHP has finished outputting the response, the script ends and nothing will happen on the server until a new HTTP request comes in.*




          Graphical representation



          Image source




          So now what can I do if I need to call PHP? It depends how you need to do it: either by reloading the page or by using an AJAX call.




          1. You can do by reloading page and send HTTP request

          2. you can make AJAX call with JavaScript and this does not require reloading page


          Good Read:




          1. Wikipedia : Server-side scripting

          2. Wikipedia : Client-side scripting

          3. Madara Uchiha : Difference between client side and server side programming







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 28 '17 at 4:55









          Alexander Nied

          3,86211130




          3,86211130










          answered Jul 1 '13 at 11:52









          NullPoiиteяNullPoiиteя

          45.9k19108128




          45.9k19108128























              24














              Your Javascript will execute on the client, not on the server. This means that foo is not evaluated on the server side and therefore its value can't be written to a file on the server.



              The best way to think about this process is as if you're generating a text file dynamically. The text you're generating only becomes executable code once the browser interprets it. Only what you place between <?php tags is evaluated on the server.



              By the way, making a habit of embedding random pieces of PHP logic in HTML or Javascript can lead to seriously convoluted code. I speak from painful experience.






              share|improve this answer



















              • 3





                Your answer here is noteworthy as it makes mention to the/a interpeter. However, javascript can be compiled and run in a server environment, and it can be interpeted by a server as well.

                – Brett Caswell
                Mar 10 '15 at 17:10
















              24














              Your Javascript will execute on the client, not on the server. This means that foo is not evaluated on the server side and therefore its value can't be written to a file on the server.



              The best way to think about this process is as if you're generating a text file dynamically. The text you're generating only becomes executable code once the browser interprets it. Only what you place between <?php tags is evaluated on the server.



              By the way, making a habit of embedding random pieces of PHP logic in HTML or Javascript can lead to seriously convoluted code. I speak from painful experience.






              share|improve this answer



















              • 3





                Your answer here is noteworthy as it makes mention to the/a interpeter. However, javascript can be compiled and run in a server environment, and it can be interpeted by a server as well.

                – Brett Caswell
                Mar 10 '15 at 17:10














              24












              24








              24







              Your Javascript will execute on the client, not on the server. This means that foo is not evaluated on the server side and therefore its value can't be written to a file on the server.



              The best way to think about this process is as if you're generating a text file dynamically. The text you're generating only becomes executable code once the browser interprets it. Only what you place between <?php tags is evaluated on the server.



              By the way, making a habit of embedding random pieces of PHP logic in HTML or Javascript can lead to seriously convoluted code. I speak from painful experience.






              share|improve this answer













              Your Javascript will execute on the client, not on the server. This means that foo is not evaluated on the server side and therefore its value can't be written to a file on the server.



              The best way to think about this process is as if you're generating a text file dynamically. The text you're generating only becomes executable code once the browser interprets it. Only what you place between <?php tags is evaluated on the server.



              By the way, making a habit of embedding random pieces of PHP logic in HTML or Javascript can lead to seriously convoluted code. I speak from painful experience.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 12 '12 at 13:46









              NitayArtNitayArt

              30616




              30616








              • 3





                Your answer here is noteworthy as it makes mention to the/a interpeter. However, javascript can be compiled and run in a server environment, and it can be interpeted by a server as well.

                – Brett Caswell
                Mar 10 '15 at 17:10














              • 3





                Your answer here is noteworthy as it makes mention to the/a interpeter. However, javascript can be compiled and run in a server environment, and it can be interpeted by a server as well.

                – Brett Caswell
                Mar 10 '15 at 17:10








              3




              3





              Your answer here is noteworthy as it makes mention to the/a interpeter. However, javascript can be compiled and run in a server environment, and it can be interpeted by a server as well.

              – Brett Caswell
              Mar 10 '15 at 17:10





              Your answer here is noteworthy as it makes mention to the/a interpeter. However, javascript can be compiled and run in a server environment, and it can be interpeted by a server as well.

              – Brett Caswell
              Mar 10 '15 at 17:10











              3














              In web application every task execute in a manner of request and response.



              Client side programming is with html code with Java script and its frameworks, libraries executes in the internet explorer, Mozilla, chrome browsers.
              In the java scenario
              server side programming servlets executes in the Tomcat, web-logic , j boss, WebSphere severs






              share|improve this answer




























                3














                In web application every task execute in a manner of request and response.



                Client side programming is with html code with Java script and its frameworks, libraries executes in the internet explorer, Mozilla, chrome browsers.
                In the java scenario
                server side programming servlets executes in the Tomcat, web-logic , j boss, WebSphere severs






                share|improve this answer


























                  3












                  3








                  3







                  In web application every task execute in a manner of request and response.



                  Client side programming is with html code with Java script and its frameworks, libraries executes in the internet explorer, Mozilla, chrome browsers.
                  In the java scenario
                  server side programming servlets executes in the Tomcat, web-logic , j boss, WebSphere severs






                  share|improve this answer













                  In web application every task execute in a manner of request and response.



                  Client side programming is with html code with Java script and its frameworks, libraries executes in the internet explorer, Mozilla, chrome browsers.
                  In the java scenario
                  server side programming servlets executes in the Tomcat, web-logic , j boss, WebSphere severs







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 13 '16 at 9:26









                  chandrashekar.nchandrashekar.n

                  1548




                  1548























                      0














                      I will try to explain it in simple way.



                      Client Side is what user see/ code which is visible on browser.



                      Client Side Programming includes HTML(HTML, HTML5, DHTML), CSS(CSS, CSS3) and JavaScript(JavaScript, ES5, ES6, ES7, TypeScript, JQuery, ReactJs, AngularJs, BackboneJs or any other JavaScript Front-end framework).



                      Client Side programming focus on "how page will look like" and its behavior over browsers.




                      1. HTML is what we see.

                      2. CSS decides its designing(Colours, Floating Images, Padding, etc).

                      3. JavaScript monitor page information. All the API calls and maintaining data over DOM is done by JavaScript.


                      Server Side Programming includes code which provide data to Client-Side. User is never able to see server-side.



                      Server Side Programming involves Programming Language(Java, PHP, .Net, C#, C, C++, NodeJS etc), Database(SQL, Oracle, MySql, PostgreySql, No-Sql, MongoDB, etc), Third Party API(Rest, Soap), Business Logic.



                      Server Side Programming focus on "how to make data available for Client-Side".




                      1. Server-Side Language is responsible for communicating between different source of data like database, third-party API, file system, blockchain etc,. These languages maintain certain API for client-side to interact with.

                      2. Database is responsible for storing information.

                      3. Business Logic defines "how to use data and what to do with data".


                      Client-Side request data or request to store data, from Server-side via API provided by Server-Side. This request and response of data is done by following HTTP/FTP protocol like REST API, SOAP API.






                      share|improve this answer





















                      • 1





                        While this tries to answer the question posed in the title, it completely ignores the detail of the question body so doesn't address the problem at all.

                        – Quentin
                        Oct 22 '18 at 11:20


















                      0














                      I will try to explain it in simple way.



                      Client Side is what user see/ code which is visible on browser.



                      Client Side Programming includes HTML(HTML, HTML5, DHTML), CSS(CSS, CSS3) and JavaScript(JavaScript, ES5, ES6, ES7, TypeScript, JQuery, ReactJs, AngularJs, BackboneJs or any other JavaScript Front-end framework).



                      Client Side programming focus on "how page will look like" and its behavior over browsers.




                      1. HTML is what we see.

                      2. CSS decides its designing(Colours, Floating Images, Padding, etc).

                      3. JavaScript monitor page information. All the API calls and maintaining data over DOM is done by JavaScript.


                      Server Side Programming includes code which provide data to Client-Side. User is never able to see server-side.



                      Server Side Programming involves Programming Language(Java, PHP, .Net, C#, C, C++, NodeJS etc), Database(SQL, Oracle, MySql, PostgreySql, No-Sql, MongoDB, etc), Third Party API(Rest, Soap), Business Logic.



                      Server Side Programming focus on "how to make data available for Client-Side".




                      1. Server-Side Language is responsible for communicating between different source of data like database, third-party API, file system, blockchain etc,. These languages maintain certain API for client-side to interact with.

                      2. Database is responsible for storing information.

                      3. Business Logic defines "how to use data and what to do with data".


                      Client-Side request data or request to store data, from Server-side via API provided by Server-Side. This request and response of data is done by following HTTP/FTP protocol like REST API, SOAP API.






                      share|improve this answer





















                      • 1





                        While this tries to answer the question posed in the title, it completely ignores the detail of the question body so doesn't address the problem at all.

                        – Quentin
                        Oct 22 '18 at 11:20
















                      0












                      0








                      0







                      I will try to explain it in simple way.



                      Client Side is what user see/ code which is visible on browser.



                      Client Side Programming includes HTML(HTML, HTML5, DHTML), CSS(CSS, CSS3) and JavaScript(JavaScript, ES5, ES6, ES7, TypeScript, JQuery, ReactJs, AngularJs, BackboneJs or any other JavaScript Front-end framework).



                      Client Side programming focus on "how page will look like" and its behavior over browsers.




                      1. HTML is what we see.

                      2. CSS decides its designing(Colours, Floating Images, Padding, etc).

                      3. JavaScript monitor page information. All the API calls and maintaining data over DOM is done by JavaScript.


                      Server Side Programming includes code which provide data to Client-Side. User is never able to see server-side.



                      Server Side Programming involves Programming Language(Java, PHP, .Net, C#, C, C++, NodeJS etc), Database(SQL, Oracle, MySql, PostgreySql, No-Sql, MongoDB, etc), Third Party API(Rest, Soap), Business Logic.



                      Server Side Programming focus on "how to make data available for Client-Side".




                      1. Server-Side Language is responsible for communicating between different source of data like database, third-party API, file system, blockchain etc,. These languages maintain certain API for client-side to interact with.

                      2. Database is responsible for storing information.

                      3. Business Logic defines "how to use data and what to do with data".


                      Client-Side request data or request to store data, from Server-side via API provided by Server-Side. This request and response of data is done by following HTTP/FTP protocol like REST API, SOAP API.






                      share|improve this answer















                      I will try to explain it in simple way.



                      Client Side is what user see/ code which is visible on browser.



                      Client Side Programming includes HTML(HTML, HTML5, DHTML), CSS(CSS, CSS3) and JavaScript(JavaScript, ES5, ES6, ES7, TypeScript, JQuery, ReactJs, AngularJs, BackboneJs or any other JavaScript Front-end framework).



                      Client Side programming focus on "how page will look like" and its behavior over browsers.




                      1. HTML is what we see.

                      2. CSS decides its designing(Colours, Floating Images, Padding, etc).

                      3. JavaScript monitor page information. All the API calls and maintaining data over DOM is done by JavaScript.


                      Server Side Programming includes code which provide data to Client-Side. User is never able to see server-side.



                      Server Side Programming involves Programming Language(Java, PHP, .Net, C#, C, C++, NodeJS etc), Database(SQL, Oracle, MySql, PostgreySql, No-Sql, MongoDB, etc), Third Party API(Rest, Soap), Business Logic.



                      Server Side Programming focus on "how to make data available for Client-Side".




                      1. Server-Side Language is responsible for communicating between different source of data like database, third-party API, file system, blockchain etc,. These languages maintain certain API for client-side to interact with.

                      2. Database is responsible for storing information.

                      3. Business Logic defines "how to use data and what to do with data".


                      Client-Side request data or request to store data, from Server-side via API provided by Server-Side. This request and response of data is done by following HTTP/FTP protocol like REST API, SOAP API.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 22 '18 at 17:17

























                      answered Aug 22 '18 at 7:38









                      NAVINNAVIN

                      1,6793725




                      1,6793725








                      • 1





                        While this tries to answer the question posed in the title, it completely ignores the detail of the question body so doesn't address the problem at all.

                        – Quentin
                        Oct 22 '18 at 11:20
















                      • 1





                        While this tries to answer the question posed in the title, it completely ignores the detail of the question body so doesn't address the problem at all.

                        – Quentin
                        Oct 22 '18 at 11:20










                      1




                      1





                      While this tries to answer the question posed in the title, it completely ignores the detail of the question body so doesn't address the problem at all.

                      – Quentin
                      Oct 22 '18 at 11:20







                      While this tries to answer the question posed in the title, it completely ignores the detail of the question body so doesn't address the problem at all.

                      – Quentin
                      Oct 22 '18 at 11:20







                      protected by Alma Do Aug 11 '14 at 9:41



                      Thank you for your interest in this question.
                      Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                      Would you like to answer one of these unanswered questions instead?



                      Popular posts from this blog

                      Guess what letter conforming each word

                      Port of Spain

                      Run scheduled task as local user group (not BUILTIN)