开发者

PHP shell command not executed via AJAX-call

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜