dongxie5698 2010-05-20 20:04
浏览 41
已采纳

你可以在CGI脚本的输出中嵌入PHP代码吗?

I have a CGI based form that I am working with and I would like to be able to include some PHP code in the generated results. However, when I do this, the PHP does not appear to get processed and just ends up being displayed in the resulting web page.

Is what I am doing actually possible or am I missing something?

Thanks.

  • 写回答

4条回答 默认 最新

  • dqjl0906 2010-05-20 20:08
    关注

    No, that's not possible. You could however, in a PHP script, include('http://url.to/cgi/script'); and then point your browser at the PHP script rather than the CGI script. This will cause PHP to open a new connection to the server, execute the CGI script, and then parse it's output as if it were a PHP script.

    EDIT2: Here's how you could do it with postdata including file uploads:

    // Edit to match your CGI URI:
    $url_to_cgi = "http://{$_SERVER['SERVER_NAME']}/cgi-bin/something.cgi";
    
    $curl = curl_init($url_to_cgi);
    curl_setopt($curl,CURLOPT_POST, true);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
    
    // Pass POSTDATA along to the CGI script:
    $postdata = $_POST;
    
    // If we have file uploads, pass those along too:
    if(is_array($_FILES)) foreach($_FILES as $key => $file)
      $post[$key] = "@{$file['tmp_name']}";
    
    curl_setopt($curl,CURLOPT_POSTFIELDS, $postdata);
    
    $file = tempnam('/tmp','php-curl-');
    file_put_contente($file, curl_exec($curl);
    
    include($file);
    
    unlink($file);
    

    Please note that's untested...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?