How to pass a php variable to shell_exec

Asked

Viewed 128 times

1

How do I pass an input or select value as a variable to a shell_exec ?

I have the following form:

<form action="speedtest.php" method="POST" id="SpeedTest" class="form">
  <p>
    <label>Quantidade de testes a serem executados: </label>
  </p>
  <input type="tel" name="testes" class="testes" maxlength="1" required>
  <button type="submit" class="qts" value="Executar" onclick="Oculta('main')">Executar</button>
</form>

This form sends the amount of speed test runs that will be done on the server. Below I have the script that runs the speed tests:

<?php

shell_exec('/bin/speedtest -l');

?>

The "value" variable coming from the input form would enter the middle of "Speedtest -l", for example, if you filled in 2 in the input that number would enter this way in shell_exec: Speedtest 2 -l

Any suggestions on how I can do this?

  • Someone who can help me with that ?

1 answer

1


I hope it helps

<?php

    $qtdteste = $_POST['testes'];

    shell_exec('/bin/speedtest '.$qtdteste.' -l');
  • 1

    I had already solved, but thank you very much for the answer, help someone when you need something like me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.