dongxie5698 2010-05-20 12: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 12: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了