douqin6785 2011-09-09 13:07
浏览 63
已采纳

PHP exec在直接调用脚本时有效,但不是由jQuery ajax调用

I have a PHP script which calls exec(). I've been having trouble all day with some code calling the same script working and some not (exec() returns a 127 error code).

I have finally worked out that the code that is not working is the code that is being called from jQuery on my web page:

$('#next_button').click(function(event) {
    $.get('download_forms.php', function(data) {
        alert(data);
    });
});

However, if I type the url for download_forms.php into the address bar of my browser, then exec() will execute properly. I have tries to run other scripts that call exec() from jQuery to test and they all fail, but work if typed into the address bar.

I don't see why this would be an issue. Whether I type the url into Firefox's address bar, or whether pressing the button on my webpage, an HTTP request will be made.

Does anybody know what the difference could possibly be?

Note: I have tried different commands in exec() and they are all failing from my jQuery (note all the rest of the PHP code runs fine) but work when the script address is typed directly into the address bar.

Many thanks

Update

This is my download_forms.php code. The initial exec() was just to see if exec() worked at all. As above, it only executes properly if typed directly into the address bar.

include ('inc/session.inc.php');
require_once('Downloader.php');
exec('id', $output, $r);
echo var_dump($output);
echo($r);
try {
    $downloader = new Downloader();
    $saveMessages = $downloader->saveToDatabase();
    // exec() in the combineAndDownloadForms() method
    $downloadMessages = $downloader->combineAndDownloadForms();
} catch(Exception $e) {
    echo $e->getMessage();
}

Further Update

I made a hyperlink through from my webpage to the download_forms.php page (ie a <a>), but exec() still doesn't execute. At least I know it's nothing to do with ajax.

展开全部

  • 写回答

1条回答 默认 最新

  • dsms21398 2011-09-16 00:11
    关注

    For what it's worth, I fixed this issue and all of the above was a red herring.

    I hadn't noticed that the page I was on was using the secure https protocol, so when the download_forms.php script was being used, it was also accessed using https and it seems that the exec() and passthru() functions won't execute commands on the server in these circumstances, which makes sense.

    I changed the script so that it changed the protocol of the download_forms.php url to ordinary http and it's now functioning fine.

    HTH

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部