Insert PHP code into JavaScript is impossible, there is a technique, not too complicated, which makes the procedure feasible, in general you should use this type of embedding only when absolutely necessary, it better not to add any vulnerability.
To insert PHP code in JavaScript you must first create a .htacces within which include some simple instructions:
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;"><FilesMatch "^.*\.js$"></span> <FilesMatch "^.*\.js$"></span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">SetHandler php5-script</span> SetHandler php5-script</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;"></FilesMatch></span> </ FilesMatch></span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;"><FilesMatch "^.*\.js$"></span> <FilesMatch "^.*\.js$"></span>The file will be saved in the root of the web server or the folder where you want to make valid directives enter at this point do is go to the real embedding. At the beginning of your Javascript file (. Js) add the following code:
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;"><?php</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">// definizione del Content Type</span> / / Definition of the Content Type</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">@header("Content-type: application/javascript");</span> @ Header ("Content-type: application / javascript");</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">?></span> ?></span>
With the high definition of the correct Content Type interpret the client page (where this PHP code) like a simple JavaScript file. See a very banal example of a hypothetical file esempio.js “
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;"><?php</span> <? Php</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">// definizione del Content Type</span> / / Definition of the Content Type</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">@header("Content-type: application/javascript");</span> @ Header ("Content-type: application / javascript");</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">// definisco una variabile</span> / / Define variable</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">$testo = "Ciao a tutti!";</span> $ Text = "Hello World";</span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">?></span> ?></span>
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left;">alert('<?php echo $testo; ?>');</span> alert ('<? php echo $ text; ?>');</span>