0

If I run startIRsend.php from the comamnd line, it works. If I try to start it from my HTML button the PHP code prints nothing in the terminal.

home.html:

<html>
<head>
</head>
<body>
<form action="startIRsend.php" method="post">
 <input type="submit" value="Run me now!">
</form>
</body>
</html>

startIRsend.php

<?php
echo "hi";
?>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Tappo
  • 31
  • 3
  • what happens when you click the Run me now! button? – madalinivascu Aug 05 '19 at 09:57
  • 1
    why do you think something will be printed on the terminal window when you are running the page from a browser? – madalinivascu Aug 05 '19 at 09:58
  • @madalinivascu when click on the button the php code is shown – Tappo Aug 05 '19 at 10:07
  • @madalinivascu If I start directly the php with sudo php startIRsend.php in the terminal I see the output "hi", I think it is the same if I start the php code from an html command. isn't it? – Tappo Aug 05 '19 at 10:14
  • 2
    when you call `startIRsend.php` from the browser you will get the result in the browser not in the terminal – madalinivascu Aug 05 '19 at 10:56
  • 1
    What is the relationship between the terminal and the HTTP server the browser is making the request to? – Quentin Aug 05 '19 at 11:53
  • _when click on the button the PHP code is shown_ You are sure you are making the req to the web server and not the file? I mean to the localhost. Do `localhost/startIRsend.php` in the url – weegee Aug 05 '19 at 11:57
  • 2
    "same if I start the php code from an html command" ...no. I'm not sure where you got this idea from? What will usually happen in this case is the PHP interpreter will be executed by the webserver (e.g. Apache) and will return the response back to the webserver, which will then forward it back to the browser. That's how PHP is used as the backend for web applications. If you want, you could get the PHP code to also log things elsewhere (e.g. to disk or database, but not to a live terminal (and anyway it would be located on the server machine, not the machine where the browser is running)). – ADyson Aug 05 '19 at 11:57
  • However if you are simply seeing the PHP code listed in the browser (instead of seeing the output of executing the PHP), then this suggests that PHP and the webserver are not properly set up to handle HTTP requests in this way. See [this post](https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) for relevant information about setting this up correctly. – ADyson Aug 05 '19 at 13:05

0 Answers0