How do I run PHP script without creating an executable?
Just as you can link to a .JS page using <script type="text… , I’d like to keep my home page as an .HTML file, but I need to grab some variables from some PHP script.
All answers so far are off the mark.
Your web server needs to be configured to see that HTML files (as in, the file extension, not the content of the file) as able to contain PHP scripts in them.
To be clear… most php-enabled pages have the file extension of ".php", and that tells the web server software to expect PHP scripts in the file.
Many web servers do NOT expect PHP scripting in a .html file (like index.html versus index.php), so it will simply echo out the PHP script to the page, rather than parsing the PHP, etc…
TO be even more clear, PHP is not a "program". You can’t make a PHP executable. PHP is a text script that is interpreted by the PHP parser on the web server.
Anyway… the answer to your question is… suck it up and name your web page files whatever.php instead of whatever.html… the file extension shouldn’t matter to the end user, but it matters to the web server.
Alternately, you can set up your web server to see files ending with .html to expect PHP within them, so PHP will be parsed… but that’s a pain, so why not just use the .php file extension?
<?php
$var = $_REQUEST['parameter name'];
?>
PHP runs on the server, HTML runs on the client. PHP is programming, HTML is content.
About the closest you can do is to submit a form to a PHP page. (Or use Javascript on the HTML page, and AJAX to communicate between the two.)
That’s what Ajax is for.
Run an XMLHttpRequest using JavaScript, let a separate PHP script take the call and answer it, and JavaScript takes over again.
You can treat the result as a JavaScript command or function (JSON), or return it as either plain text or XML.