简体   繁体   English

执行一个PHP来执行shell脚本

[英]exec a php to execute shell script

I have a php script like this. 我有这样的PHP脚本。 This doesn't run my script nor print anything on the click of the button. 单击该按钮不会运行我的脚本,也不会打印任何内容。 How to do that Also if you have a pointer to php 101 online please let me know 如何做到这一点另外,如果您在线有PHP 101的指针,请告诉我

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
ob_start();

passthru("./check_ddts.sh ".escapeshellarg($_POST["CSCui21515"]));
$data = ob_get_clean();
}
?>


<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<button type="button" onclick="?run=true">Click Me!</button>

Your button is not actually doing anything. 您的按钮实际上没有执行任何操作。 The problem is that your onclick attribute should contain javascript which will run when the button is clicked, not a redirect location. 问题在于您的onclick属性应包含将在单击按钮时运行的javascript,而不是重定向位置。 Use a form with a submit button instead like this. 而是使用带有提交按钮的表单。

<form action="" method="get">
    <input type="submit" name="run" value="Click Me!" />
</form>

I notice in your question that you are also using post data in handling the form, in which case the above will not work. 我在您的问题中注意到,您还在处理表单时使用过帐数据,在这种情况下,上述方法将不起作用。 You need to submit the POST data at the same time as you run the script. 您需要在运行脚本的同时提交POST数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM