开发者

PHP shell command not executed via AJAX-call

开发者 https://www.devze.com 2023-03-17 20:06 出处:网络
In my homeserver management application I added a function to wake PC\'s remotely via the application.

In my homeserver management application I added a function to wake PC's remotely via the application. The PHP-script that does this works perfectly, but I want to be able to do this via an AJAX-call.

The call happens like this:

User clicks a PHP-generated link:

<a href=\"javascript:wake('$hostname')\">Wake</a>

Where the function (jQuery) is:

function wake(hostname) {
    $(document).ready(function()
    {
       alert('function works');
       $.post('ajax/wake.php',{host: hostname});
       alert('Command executed');
    });
}

Both alerts are shown, which means the AJAX-call is executed. The php-script looks like this:

<?php
include_once("../classes/BLClient.php");
$blClient = new BLClient(true);
$hostname = $_GET["host"];

$client = $blClient->getClientByHostname($hostname);
$mac = $client->getMac();

ec开发者_StackOverflow社区ho `sudo etherwake -i eth1 $mac`;
?>

However, my PC's are not woken. If I browse directly to the script, it does work...


You're firing a $.post ajax request, but you're reading a $_GET parameter in your PHP script. Do a $.get ajax request instead, otherwise the data will be in $_POST not in $_GET.

Alternatively you can make use of the $_REQUEST superglobal which contains both post and get variables in PHP.


you might need to use

$_POST["host"] or $_REQUEST["host"] in your php script, as you are doing a Jquery post.

In the browser, you might be passing host like :

 http://www.mysite.com/ajax/wake.php?host=xxxxxxxx

Which results in "host" being present in $_GET .


Yor are making post call '$.post' ,so here you have to use "$_POST["host"]"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号