1

let's say I have a php page with a javascript script (script src...) can I use innerHTML to put additional php code in it? lets say

document.getElementsByTagName("body").innerHTML = "<?php $test=90312; echo $test; ?>";

will this get executed?

Thanks

1
  • Why do you need that? Decare first $test in PHP, then assign its value to js var, then append innerHTML to the js variable. Since a declared but not used PHP var has nothing to do with what the user sees, you don't need to additinally add PHP that does not do anything (I mean the part "$test=90312;") Commented Aug 16, 2013 at 21:09

2 Answers 2

2

No, the PHP will not be executed. PHP is executed server-side, while JavaScript is not executed until after the webpage has been loaded by the browser (client side), so it has no way to run the PHP (unless you're using a very odd browser).

Sign up to request clarification or add additional context in comments.

Comments

0

Yes it will be executed php first and render the result in its place together with the javascript before sending it to the browser client in which case the javascript is then executed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.