View Full Version : Activating PHP code with Javascript - Help Please...

01-10-2007, 10:08 AM
Is there a way for me to activate php code on my page - perhaps with a button? Or are there any other methods?


01-10-2007, 10:14 AM
I think you should have a look at this resource (http://www.phpbuilder.com/tips/item.php?id=874)

01-10-2007, 10:18 AM
That's a very simplified version of "AJAX." See this tutorial (http://www.w3schools.com/ajax/default.asp) for a generally preferable way of doing it -- the XHR object means that it's no longer necessary to bother with the iframe at all.

01-10-2007, 10:33 AM
Looking at the tutorials now. Thanks very much!

01-10-2007, 11:24 AM
Wait. Using JavaScript to load PHP completely eliminates the purpose of PHP. When you write out PHP commands, when the user views the code, all she/he sees is the PHP output. With Javascript you can see all the variables, commands, etc. Doing so would enable a user to view your PHP code.
I'm thinking these resources may have a security leak.

01-10-2007, 11:42 AM
You're wrong.

Certain variables will be revealed to the client, yes, but these needn't be sensitive. If one wished to use Javascript to retrieve the address of a client on demand, for example, one would simply pass the client's name or ID to the PHP script. This is not sensitive information. The PHP script is the only part that touches the sensitive information such as the database access details.

01-10-2007, 02:06 PM
Remember, Javascript only retrieves the visible elements of PHP. It's just like refreshing the page a bunch of times... you get some output, but it's not the secure data inside the PHP code.