doubei2340 2011-07-22 13:37
浏览 34
已采纳

PHP侦听器脚本,可以读取传入的$ _REQUEST或$ _POST变量

I am trying to write a PHP script that listens for incoming $_REQUEST or $_POST variables that are sent by a web application as part of a 2-way communication.

HTTP GET calls will be made to the web app in format similar to this.

The WEBAPP will then send a POST response to my listener script (http://TRAVISNG.com/listener.php) and so I was wondering if my php script could parse it without me executing the php script manually?

Note that I am not referring to writing a script that listens for network requests on a socket.

Basically, I want to parse the POST data sent by the web app and write it out to a log file. Therefore, every time I run my listener script it will read the log file and print out all the POST responses sent to my listener script.

Here's some of the code that I've written:

<?php

    // Read incoming POST request
    if (!empty($_POST)){
        $params = join(" ", $_POST);
        //print_r($params);
        echo "|$params|";
    }

    // Print params & timestamp to file called listenerLog.txt
    $logFile = "http://travisng.com/listenerLog.txt";

    $fileHandle = fopen($logFile, 'a') or die("Unable to open the listenerLog.txt.");
    fwrite($fileHandle, $params);
    fclose($fileHandle);

    $output = file_get_contents($logFile);

    // Print listenerLog.txt
    //echo $output;

?>

Cheers,

Travis

  • 写回答

2条回答 默认 最新

  • doujingxi3356 2012-03-22 00:05
    关注

    To overcome this issue, I decided to create a CGI listener script and process REQUEST parameters from there. The CGI script was invoked whenever a GET/POST request came through and the requests were written out to a log file.

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

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂